{"id":18367149,"url":"https://github.com/amoutonbrady/tiny-http","last_synced_at":"2025-04-06T16:32:31.803Z","repository":{"id":57097267,"uuid":"282062259","full_name":"amoutonbrady/tiny-http","owner":"amoutonbrady","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-03T06:05:31.000Z","size":84142,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-17T19:59:57.255Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amoutonbrady.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-23T21:47:30.000Z","updated_at":"2021-09-19T03:01:08.000Z","dependencies_parsed_at":"2022-08-20T18:10:19.865Z","dependency_job_id":null,"html_url":"https://github.com/amoutonbrady/tiny-http","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoutonbrady%2Ftiny-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoutonbrady%2Ftiny-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoutonbrady%2Ftiny-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoutonbrady%2Ftiny-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amoutonbrady","download_url":"https://codeload.github.com/amoutonbrady/tiny-http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247512958,"owners_count":20950963,"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":[],"created_at":"2024-11-05T23:20:14.405Z","updated_at":"2025-04-06T16:32:31.548Z","avatar_url":"https://github.com/amoutonbrady.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tiny-http\n\n\u003cp\u003e\n    \u003ca href=\"https://bundlephobia.com/result?p=@amoutonbrady/tiny-http\"\u003e\n      \u003cimg src=\"https://badgen.net/bundlephobia/min/@amoutonbrady/tiny-http\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://www.pika.dev/npm/@amoutonbrady/tiny-http\"\u003e\n      \u003cimg src=\"https://badgen.net/npm/v/@amoutonbrady/tiny-http\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nA tiny client side HTTP client, light and extensible\n\n- ✔ Extensible, everything is pretty much a middleware\n- ✔ Light, no dependencies\n- ✔ Tailored, tree shakeable, use only what you need\n- ✔ TS ready, written 100% in Typescript\n\n## Installation\n\n`npm install @amoutonbrady/tiny-http`\n\n### Options\n\n```ts\ntype Pipe = (options: Options) =\u003e Options;\ntype ResponsePiper\u003cT1 = any, T2 = any\u003e = (res: T1) =\u003e T2;\ntype ErrorPiper\u003cT1 = Error, T1 = Error\u003e = (err: T1) =\u003e T2;\n\ninterface Options {\n  url: string;\n  middlewares: Pipe[];\n  responseType: 'json' | 'blob' | 'text' | 'arrayBuffer' | 'formData' | 'clone';\n  headers: Record\u003cstring, string\u003e;\n  params: URLSearchParams;\n  preResolvers: ((res: Response, value: T) =\u003e void)[];\n  resolvers: ResponsePiper[];\n  catchers: ErrorPiper[];\n  fetchOptions: RequestInit;\n}\n```\n\nYou can feed these options to a brand new `http()` call:\n\n```ts\nconst client = http({\n  url: \"http://localhost\",\n  headers: {\n    \"Content-Type\": \"application/json\",\n  },\n  ...\n})\n\nconst [error, response] = await client.get\u003cstring\u003e(\"/test\");\n```\n\nor/and pipe the client to modify them as you please\n\n```ts\nimport {\n  http,\n  url,\n  headers,\n  params,\n  middleware,\n  resolve,\n  json,\n  error,\n} from '@amoutonbrady/tiny-http';\n\nconst client = http().pipe(\n  url('http://localhost', true), // Replace the URL, the second parameter is to replace or append\n  headers({ 'Content-Type': 'application/json' }),\n  params({ test: 'trololol' }),\n  middleware((opts) =\u003e opts), // Pretty much useless as you can just do (opts) =\u003e opts\n  json(), // sets responseType to `json`\n  resolve((res) =\u003e res), // Ran after the responseType is resolved fetch(url).then(r =\u003e r.json()).r(myResolver)\n  error((err) =\u003e err),\n);\n\nconst [error, response] = await client.get\u003cstring\u003e('/test');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famoutonbrady%2Ftiny-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famoutonbrady%2Ftiny-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famoutonbrady%2Ftiny-http/lists"}