{"id":15674574,"url":"https://github.com/417-72ki/multipartformdataparser","last_synced_at":"2025-04-30T13:52:49.153Z","repository":{"id":36543861,"uuid":"227887282","full_name":"417-72KI/MultipartFormDataParser","owner":"417-72KI","description":"Testing tool for `multipart/form-data`","archived":false,"fork":false,"pushed_at":"2025-03-23T18:14:20.000Z","size":325,"stargazers_count":14,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T16:46:31.125Z","etag":null,"topics":["ios","macos","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/417-72KI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-13T17:08:09.000Z","updated_at":"2024-10-22T00:15:42.000Z","dependencies_parsed_at":"2022-08-08T15:30:26.712Z","dependency_job_id":"bb50ce70-a639-4e8a-b2ff-b425780d29e9","html_url":"https://github.com/417-72KI/MultipartFormDataParser","commit_stats":{"total_commits":248,"total_committers":5,"mean_commits":49.6,"dds":0.05241935483870963,"last_synced_commit":"268e15ba22aec3a13ab991bef978b627a4abbbf6"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/417-72KI%2FMultipartFormDataParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/417-72KI%2FMultipartFormDataParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/417-72KI%2FMultipartFormDataParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/417-72KI%2FMultipartFormDataParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/417-72KI","download_url":"https://codeload.github.com/417-72KI/MultipartFormDataParser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251714965,"owners_count":21631812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","macos","swift"],"created_at":"2024-10-03T15:47:04.186Z","updated_at":"2025-04-30T13:52:49.130Z","avatar_url":"https://github.com/417-72KI.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MultipartFormDataParser\n[![Actions Status](https://github.com/417-72KI/MultipartFormDataParser/workflows/Test/badge.svg)](https://github.com/417-72KI/MultipartFormDataParser/actions)\n[![Version](http://img.shields.io/cocoapods/v/MultipartFormDataParser.svg?style=flat)](http://cocoapods.org/pods/MultipartFormDataParser)\n[![Platform](http://img.shields.io/cocoapods/p/MultipartFormDataParser.svg?style=flat)](http://cocoapods.org/pods/MultipartFormDataParser)\n[![GitHub release](https://img.shields.io/github/release/417-72KI/MultipartFormDataParser/all.svg)](https://github.com/417-72KI/MultipartFormDataParser/releases)\n[![Swift Package Manager](https://img.shields.io/badge/Swift%20Package%20Manager-5.7-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F417-72KI%2FMultipartFormDataParser%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/417-72KI/MultipartFormDataParser)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F417-72KI%2FMultipartFormDataParser%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/417-72KI/MultipartFormDataParser)\n[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/417-72KI/MultipartFormDataParser/master/LICENSE)\n\n`MultipartFormDataParser` is a testing tool for `multipart/form-data` request in Swift.\n\nWhen to upload some files via API, we must use `multipart/form-data` for request.\n`multipart/form-data` is defined as [RFC-2388](https://www.ietf.org/rfc/rfc2388.txt)\n\nMost famous networking libraries (e.g. [Alamofire](https://github.com/Alamofire/Alamofire), [APIKit](https://github.com/ishkawa/APIKit)) can implement easily.\nHowever, to test if the created request is as expected is difficult and bothering.\n\nThis library provides a parser for `multipart/form-data` request to test it briefly.\n\n```swift\nlet request: URLRequest = ...\ndo {\n    let data = try MultipartFormData.parse(from: request)\n    let genbaNeko = try XCTUnwrap(data.element(forName: \"genbaNeko\"))\n    let message = try XCTUnwrap(data.element(forName: \"message\"))\n    XCTAssertNotNil(Image(data: genbaNeko.data))\n    XCTAssertEqual(genbaNeko.mimeType, \"image/jpeg\")\n    XCTAssertEqual(message.string, \"Hello world!\")\n} catch {\n    XCTFail(error.localizedDescription)\n}\n```\n\nUsing [OHHTTPStubs](https://github.com/AliSoftware/OHHTTPStubs), we can test a request created by networking libraries easily.\n```swift\nlet expectedGenbaNeko: Data = ...\n\nlet condition = isHost(\"localhost\") \u0026\u0026 isPath(\"/upload\")\nstub(condition: condition) { request in\n    let errorResponse = { (message: String) -\u003e HTTPStubsResponse in\n        .init(\n            jsonObject: [\"status\": 403, \"error\": message],\n            statusCode: 403, \n            headers: [\"Content-Type\": \"application/json\"]\n        )\n    }\n    do {\n        let data = try MultipartFormData.parse(from: request)\n        guard let genbaNeko = data.element(forName: \"genbaNeko\"),\n              genbaNeko.data == expectedGenbaNeko else { return errorResponse(\"Unexpected genbaNeko\") }\n        guard let message = data.element(forName: \"message\"),\n              message.string == \"Hello world!\" else { return errorResponse(\"Unexpected message: \\(message)\") }\n    } catch {\n        return .init(error: error)\n    }\n    return .init(\n        jsonObject: [\"status\": 200],\n        statusCode: 200,\n        headers: [\"Content-Type\": \"application/json\"]\n    )\n}\n```\n\n## Installation\n### Swift Package Manager (recommended)\nPackage.swift\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/417-72KI/MultipartFormDataParser.git\", from: \"2.3.1\")\n]\n```\n\n### CocoaPods\nPodfile\n\n```ruby\npod 'MultipartFormDataParser'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F417-72ki%2Fmultipartformdataparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F417-72ki%2Fmultipartformdataparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F417-72ki%2Fmultipartformdataparser/lists"}