{"id":49527769,"url":"https://github.com/pvzig/parcel","last_synced_at":"2026-05-02T04:04:34.287Z","repository":{"id":349832509,"uuid":"1177152809","full_name":"pvzig/Parcel","owner":"pvzig","description":"Browser HTTP client for SwiftWASM using Codable for requests and responses.","archived":false,"fork":false,"pushed_at":"2026-04-07T18:24:46.000Z","size":127,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-07T20:04:05.018Z","etag":null,"topics":[],"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/pvzig.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-03-09T18:43:54.000Z","updated_at":"2026-04-07T18:24:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/pvzig/Parcel","commit_stats":null,"previous_names":["pvzig/parcel"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/pvzig/Parcel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvzig%2FParcel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvzig%2FParcel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvzig%2FParcel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvzig%2FParcel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pvzig","download_url":"https://codeload.github.com/pvzig/Parcel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvzig%2FParcel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32522253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2026-05-02T04:03:46.941Z","updated_at":"2026-05-02T04:04:34.281Z","avatar_url":"https://github.com/pvzig.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parcel\n\nParcel is a small browser HTTP client for SwiftWASM with pluggable typed body codecs. It defaults to JSON for `Encodable` request bodies and `Decodable` responses.\n\n## Usage\n\n```swift\nstruct Request: Encodable {}\nstruct Response: Decodable {}\n\nlet client = Client()\n\nlet accepted = try await client.send(\n    .post(\n        URL(string: \"https://example.com/api/generate\")!,\n        body: Request()\n    ),\n    as: Response.self\n)\n```\n\nTyped decode consumes the response body once. `Client.Response` preserves the decoded value, the response head, and the final URL, but it does not retain raw response bytes after decoding. `HTTPBody.text()` buffers in memory and defaults to a 2 MiB cap. Raise that limit explicitly when you expect larger bodies.\n\n### Raw Requests\n\nIf you need to drop to a raw request, use `Client.raw(_:, body:timeout:)`. Raw calls do not apply codec-specific `Accept` or `Content-Type` defaults. Raw responses may carry 4xx or 5xx status codes; typed `Client.send` calls treat non-2xx responses as failures and throw `ClientError.unsuccessfulStatusCode` before decoding.\n```swift\nlet request = HTTPRequest(method: .get, url: URL(string: \"https://example.com/api/generate\")!)\nlet response = try await client.raw(request)\n\nlet statusCode = response.response.status.code\nlet bodyText = try await response.body?.text()\n```\n\n### EmptyResponse\n\nFor successful responses with no body, use `EmptyResponse`:\n```swift\nlet deleteURL = URL(string: \"https://example.com/api/delete\")!\nlet response = try await client.send(\n    .delete(deleteURL),\n    as: EmptyResponse.self\n)\n```\n\n### Custom Encoders\nIf you need custom `JSONEncoder` / `JSONDecoder` behavior, configure the default codec through `ClientConfiguration`:\n```swift\nlet client = Client(\n    configuration: ClientConfiguration(\n        defaultTimeout: .seconds(30),\n        defaultCodec: .json(\n            codec: JSONBodyCodec(\n                makeDecoder: {\n                    let decoder = JSONDecoder()\n                    decoder.keyDecodingStrategy = .convertFromSnakeCase\n                    return decoder\n                }\n            )\n        )\n    )\n)\n```\n\n### Codecs\n\nParcel includes additional built-in codecs for common wire formats: ` .formURLEncoded()`, `.plainText()`, `.rawData()`.\n\nIf you need a different typed wire format entirely, provide a custom `BodyCodec`:\n\n```swift\nenum CustomCodecError: Error {\n    case unsupported\n}\n\nstruct CustomCodec: BodyCodec {\n    func encode\u003cRequest: Encodable\u003e(_ value: Request) throws -\u003e Data {\n        throw CustomCodecError.unsupported\n    }\n\n    func decode\u003cResponse: Decodable\u003e(_ type: Response.Type, from data: Data) throws -\u003e Response {\n        throw CustomCodecError.unsupported\n    }\n}\n\nlet client = Client(\n    configuration: ClientConfiguration(\n        defaultCodec: .custom(\n            CustomCodec(),\n            requestContentType: \"application/custom\",\n            accept: [\"application/custom\"]\n        )\n    )\n)\n```\n\n## Runtime\n\nParcel is browser-oriented. `Client()` is only compiled on `wasm32` builds that include Parcel's browser transport dependencies. Host builds must inject a custom `Transport`, which is how Parcel's native unit tests exercise the higher-level client behavior. On `wasm32`, the built-in transport supports both window-style and worker-style globals; unsupported JavaScript runtimes fail requests with `ClientError.unsupportedPlatform`.\n\n`BrowserTransport` is likewise only available on those `wasm32` builds. It installs the JavaScriptKit executor when it initializes in a supported runtime.\n\nBrowser transport responses stream lazily from `ReadableStream` through `HTTPBody`. Outgoing request bodies are still buffered before Parcel passes them to `fetch`, with a 2 MiB default cap configurable via `BrowserTransport(maximumBufferedRequestBodyBytes:)`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpvzig%2Fparcel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpvzig%2Fparcel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpvzig%2Fparcel/lists"}