{"id":13626700,"url":"https://github.com/ducdetronquito/http","last_synced_at":"2025-04-16T15:31:32.583Z","repository":{"id":45212198,"uuid":"297037315","full_name":"ducdetronquito/http","owner":"ducdetronquito","description":"HTTP core types for Zig 🦴","archived":true,"fork":false,"pushed_at":"2023-04-04T06:54:35.000Z","size":69,"stargazers_count":95,"open_issues_count":3,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-02T22:27:35.217Z","etag":null,"topics":["http","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ducdetronquito.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-20T08:54:37.000Z","updated_at":"2024-05-29T09:13:04.000Z","dependencies_parsed_at":"2023-02-09T03:01:23.336Z","dependency_job_id":null,"html_url":"https://github.com/ducdetronquito/http","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducdetronquito%2Fhttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducdetronquito%2Fhttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducdetronquito%2Fhttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducdetronquito%2Fhttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ducdetronquito","download_url":"https://codeload.github.com/ducdetronquito/http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223716688,"owners_count":17191092,"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":["http","zig"],"created_at":"2024-08-01T21:02:26.998Z","updated_at":"2024-11-08T16:31:25.169Z","avatar_url":"https://github.com/ducdetronquito.png","language":"Zig","readme":"# HTTP\n\nHTTP core types for Zig inspired by Rust [http](https://github.com/hyperium/http).\n\n[![Build Status](https://api.travis-ci.org/ducdetronquito/http.svg?branch=master)](https://travis-ci.org/ducdetronquito/http) [![License](https://img.shields.io/badge/License-BSD%200--Clause-ff69b4.svg)](https://github.com/ducdetronquito/http#license) [![Requirements](https://img.shields.io/badge/zig-0.10.0-orange)](https://ziglang.org/)\n\n⚠️ I'm currently renovating an old house which does not allow me to work on [requestz](https://github.com/ducdetronquito/requestz/), [h11](https://github.com/ducdetronquito/h11/) and [http](https://github.com/ducdetronquito/http) anymore. Feel free to fork or borrow some ideas if there are any good ones :)\n\n\n## Installation\n\n*http* is available on [astrolabe.pm](https://astrolabe.pm/) via [gyro](https://github.com/mattnite/gyro)\n\n```\ngyro add ducdetronquito/http\n```\n\n## Usage\n\nCreate an HTTP request\n\n```zig\nconst Request = @import(\"http\").Request;\nconst std = @import(\"std\");\n\nvar request = try Request.builder(std.testing.allocator)\n    .get(\"https://ziglang.org/\")\n    .header(\"GOTTA-GO\", \"FAST\")\n    .body(\"\");\ndefer request.deinit();\n```\n\nCreate an HTTP response\n\n```zig\nconst Response = @import(\"http\").Request;\nconst StatusCode = @import(\"http\").StatusCode;\nconst std = @import(\"std\");\n\nvar response = try Response.builder(std.testing.allocator)\n    .status(.Ok)\n    .header(\"GOTTA-GO\", \"FAST\")\n    .body(\"\");\ndefer response.deinit();\n```\n\n## API Reference\n\n### Structures\n\n\n#### `Headers`\n##### An HTTP header list\n\n```zig\n// The default constructor\nfn init(allocator: *Allocator) Headers\n```\n\n```zig\n// Add a header name and value\nfn append(self: *Headers, name: []const u8, value: []const u8) !void\n```\n\n```zig\n// Retrieve the first matching header\nfn get(self: Headers, name: []const u8) ?Header\n```\n\n```zig\n// Retrieve a list of matching headers\nfn list(self: Headers, name: []const u8) ![]Header\n```\n\n```zig\n// Retrieve the number of headers\nfn len(self: Headers) usize\n```\n\n```zig\n// Retrieve all headers\nfn items(self: Headers) []Header\n```\n\nHeader issues are tracked here: [#2](https://github.com/ducdetronquito/http/issues/2)\n\n\n#### `Request`\n##### An HTTP request object produced by the request builder.\n\n```zig\nconst Request = struct {\n    method: Method,\n    uri: Uri,\n    version: Version,\n    headers: Headers,\n    body: []const u8,\n};\n```\n\n```zig\n// The default constructor to start building a request\nfn builder(allocator: *Allocator) RequestBuilder\n```\n\n```zig\n// Release the memory allocated by the headers\nfn deinit(self: *Request) void\n```\n\n#### `RequestBuilder`\n##### The request builder.\n\n```zig\n// The default constructor\ndefault(allocator: *Allocator) RequestBuilder\n```\n\n```zig\n// Set the request's payload.\n// This function returns the final request objet or a potential error\n// collected during the build steps\nfn body(self: *RequestBuilder, value: []const u8) RequestError!Request\n```\n\n```zig\n// Shortcut to define a CONNECT request to the provided URI\nfn connect(self: *RequestBuilder, _uri: []const u8) *RequestBuilder\n```\n\n```zig\n// Shortcut to define a DELETE request to the provided URI\nfn delete(self: *RequestBuilder, _uri: []const u8) *RequestBuilder\n```\n\n```zig\n// Shortcut to define a GET request to the provided URI\nfn get(self: *RequestBuilder, _uri: []const u8) *RequestBuilder\n```\n\n```zig\n// Shortcut to define an HEAD request to the provided URI\nfn head(self: *RequestBuilder, _uri: []const u8) *RequestBuilder\n```\n\n```zig\n// Set a request header name and value\nfn header(self: *RequestBuilder, name: []const u8, value: []const u8) *RequestBuilder\n```\n\n```zig\n// Set the request's method\nfn method(self: *RequestBuilder, value: Method) *RequestBuilder\n```\n\n```zig\n// Shortcut to define an OPTIONS request to the provided URI\nfn options(self: *RequestBuilder, _uri: []const u8) *RequestBuilder\n```\n\n```zig\n// Shortcut to define a PATCH request to the provided URI\nfn patch(self: *RequestBuilder, _uri: []const u8) *RequestBuilder\n```\n\n```zig\n// Shortcut to define a POST request to the provided URI\nfn post(self: *RequestBuilder, _uri: []const u8) *RequestBuilder\n```\n\n```zig\n// Shortcut to define a PUT request to the provided URI\nfn put(self: *RequestBuilder, _uri: []const u8) *RequestBuilder\n```\n\n```zig\n// Shortcut to define a TRACE request to the provided URI\nfn trace(self: *RequestBuilder, _uri: []const u8) *RequestBuilder\n```\n\n```zig\n// Set the request's URI\nfn uri(self: *RequestBuilder, value: []const u8) *RequestBuilder\n```\n\n```zig\n// Set the request's protocol version\nfn version(self: *RequestBuilder, value: Version) *RequestBuilder\n```\n\n#### `Response`\n##### An HTTP response object produced by the response builder.\n\n```zig\nconst Response = struct {\n    status: StatusCode,\n    version: Version,\n    headers: Headers,\n    body: []const u8,\n};\n```\n\n```zig\n// The default constructor to start building a response\nfn builder(allocator: *Allocator) ResponseBuilder\n```\n\n#### `ResponseBuilder`\n##### The response builder.\n\n```zig\n// The default constructor\ndefault(allocator: *Allocator) ResponseBuilder\n```\n\n```zig\n// Set the response's payload.\n// This function returns the final response objet or a potential error\n// collected during the build steps\nfn body(self: *ResponseBuilder, value: []const u8) ResponseError!Response\n```\n\n```zig\n// Set a response header name and value\nfn header(self: *ResponseBuilder, name: []const u8, value: []const u8) *ResponseBuilder\n```\n\n```zig\n// Set the response's status code\nfn status(self: *ResponseBuilder, value: StatusCode) *ResponseBuilder\n```\n\n```zig\n// Set the response's protocol version\nfn version(self: *ResponseBuilder, value: Version) *ResponseBuilder\n```\n\n#### `Uri`\n##### A valid URI object\n\n[Read more](https://github.com/ducdetronquito/http/blob/master/src/uri/README.md)\n\n### Enumerations\n\n#### `Method`\n##### The available request methods.\n- Connect\n- Custom\n- Delete\n- Get\n- Head\n- Options\n- Patch\n- Post\n- Put\n- Trace\n\n#### `StatusCode`\n##### The available response status codes.\n\nA lot; the list is available on [MDN](https://developer.mozilla.org/fr/docs/Web/HTTP/Status).\n\n#### `Version`\n##### The available protocol versions.\n- Http09\n- Http10\n- Http11\n- Http2\n- Http3\n\n\n### Errors\n\n##### `HeadersError`\n\n- OutOfMemory\n- Invalid\n\n\n##### `RequestError`\n\n- OutOfMemory\n- UriRequired\n- [URI errors](https://github.com/ducdetronquito/http/blob/master/src/uri/README.md#error)\n\n\n##### `ResponseError`\n\n- OutOfMemory\n\n## License\n\n*http* is released under the [BSD Zero clause license](https://choosealicense.com/licenses/0bsd/). 🎉🍻\n\nThe URI parser is a fork of Vexu's [zuri](https://github.com/Vexu/zuri) under the MIT License.\n","funding_links":[],"categories":["Zig","Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fducdetronquito%2Fhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fducdetronquito%2Fhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fducdetronquito%2Fhttp/lists"}