{"id":17434628,"url":"https://github.com/taktik/typescript-http-client","last_synced_at":"2025-04-13T23:50:32.190Z","repository":{"id":33228723,"uuid":"155532842","full_name":"taktik/typescript-http-client","owner":"taktik","description":"A simple TypeScript HTTP client with Promise-based API and advanced filtering support ","archived":false,"fork":false,"pushed_at":"2024-10-07T10:50:40.000Z","size":1169,"stargazers_count":5,"open_issues_count":7,"forks_count":2,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-27T14:01:36.795Z","etag":null,"topics":["filtering","http-client","http-requests","promise-api","request-filtering","typescript"],"latest_commit_sha":null,"homepage":"","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/taktik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-10-31T09:40:51.000Z","updated_at":"2024-10-07T10:50:44.000Z","dependencies_parsed_at":"2024-06-18T20:04:11.149Z","dependency_job_id":"04acc4f8-f2f6-48e0-8b7d-f40c80d60a76","html_url":"https://github.com/taktik/typescript-http-client","commit_stats":{"total_commits":86,"total_committers":8,"mean_commits":10.75,"dds":0.7209302325581395,"last_synced_commit":"06b41754e0227716bc056c4728ae1895bd00a1ae"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taktik%2Ftypescript-http-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taktik%2Ftypescript-http-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taktik%2Ftypescript-http-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taktik%2Ftypescript-http-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taktik","download_url":"https://codeload.github.com/taktik/typescript-http-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586218,"owners_count":21128998,"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":["filtering","http-client","http-requests","promise-api","request-filtering","typescript"],"created_at":"2024-10-17T09:08:00.046Z","updated_at":"2025-04-13T23:50:32.146Z","avatar_url":"https://github.com/taktik.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typescript-http-client\n[![Build Status](https://travis-ci.com/taktik/typescript-http-client.svg?branch=master)](https://travis-ci.com/taktik/typescript-http-client)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com)\n\nA simple TypeScript HTTP client with Promise-based API and advanced filtering support\n\n### Basic usage\n\n###### Simple GET request with string response:\n\n```typescript\nimport expect from 'ceylon';\nimport { Response, Request, newHttpClient } from 'typescript-http-client'\n\n(async () =\u003e {\n  // Get a new client\n  const client = newHttpClient()\n  // Build the request\n  const request = new Request('https://jsonplaceholder.typicode.com/todos/1', { responseType: 'text' })\n  // Execute the request and get the response body as a string\n  const responseBody = await client.execute\u003cstring\u003e(request)\n  expect(responseBody)\n    .toExist()\n    .toBeA('string')\n    .toBe(`{\n  \"userId\": 1,\n  \"id\": 1,\n  \"title\": \"delectus aut autem\",\n  \"completed\": false\n}`)\n})()\n```\n\n###### Typed response:\n\n```typescript\nimport expect from 'ceylon';\nimport { Response, Request, newHttpClient } from 'typescript-http-client'\n\nclass Todo {\n  completed: boolean\n  id: number\n  title: string\n  userId: number\n}\n\n(async () =\u003e {\n  // Get a new client\n  const client = newHttpClient()\n  // Build the request\n  const request = new Request('https://jsonplaceholder.typicode.com/todos/1')\n  // Execute the request and get the response body as a \"Todo\" object\n  const todo = await client.execute\u003cTodo\u003e(request)\n  expect(todo)\n    .toExist()\n    .toBeA('object')\n  expect(todo.userId)\n    .toBe(1)\n})()\n```\n\n### Filters \n\nMultiple filters can be added to the httpClient, in a certain order, forming a chain of filters.\n\nFilters can be used to:\n* Alter any request property (headers, url, body, etc...)\n* Alter any response property (headers, body, etc...)\n* Short-circuit the chain by returning a custom response without proceeding with the HTTP call, allowing for example for client-side caching.\n* Intercept some or all calls for debugging/logging purposes\n\nFilters must implement the `Filter` interface and implement the `doFilter` method:\n```typescript\ninterface Filter\u003cT, U\u003e {\n  doFilter(request: Request, filterChain: FilterChain\u003cT\u003e): Promise\u003cResponse\u003cU\u003e\u003e\n}\n```\nThe `request` parameter contains the request (possibly already modified by previous filters) and can be modified by the filter (or ignored)\n\nThe `filterChain` parameter represents the chain of filters following the current filter\n\n###### Filter full example : Transform the response body:\n\nThis example transforms the fetched Todos and modify their title\n\n```typescript\nimport expect from 'ceylon';\nimport { Response, Request, Filter, FilterChain, newHttpClient } from 'typescript-http-client'\n\nclass Todo {\n  completed: boolean\n  id: number\n  title: string\n  userId: number\n}\n\n// Transform Todos : Alter title\nclass TodoTransformer implements Filter\u003cTodo, Todo\u003e {\n  async doFilter (call: Request, filterChain: FilterChain\u003cTodo\u003e): Promise\u003cResponse\u003cTodo\u003e\u003e {\n    const response = await filterChain.doFilter(call)\n    const todo = response.body\n    todo.title = 'Modified title'\n    return response\n  }\n}\n\n(async () =\u003e {\n  // Get a new client\n  const client = newHttpClient()\n  // Add our Todo tranformer filter\n  client.addFilter(new TodoTransformer(), 'Todo transformer', {\n    // Only apply to GET request with URL starting with \n    // 'https://jsonplaceholder.typicode.com/todos/'\n    enabled(call: Request): boolean {\n      return call.method === 'GET' \u0026\u0026 \n        call.url.startsWith('https://jsonplaceholder.typicode.com/todos/')\n    }\n  })\n  // Build the request\n  const request = new Request('https://jsonplaceholder.typicode.com/todos/1')\n  // Execute the request and get the response body as an object\n  const todo = await client.execute\u003cTodo\u003e(request)\n  expect(todo)\n    .toExist()\n    .toBeA('object')\n  expect(todo.userId)\n    .toBe(1)\n  expect(todo.title)\n    .toBe('Modified title')\n})()\n```\n# Hierarchy of Filters\n\n![](images/filters.jpg)\n\n# Testing\nIn the tests, you need to first in indicate which name space you are testing, and then precise which method. Both using describe. The entity tested is the first argument of describe.\nThe second argument of describe, is a function. In the function, you need another function called: it. This function also takes two arguments. The first is a string that is usefull only for future developpers (does nothing in the code) saying what result we expect from our test, and the second is once again a method, ending with an assert this time. This last method is the test.\n\nThe hook beforeEach executes before every test.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaktik%2Ftypescript-http-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaktik%2Ftypescript-http-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaktik%2Ftypescript-http-client/lists"}