A simple TypeScript HTTP client with Promise-based API and advanced filtering support
Simple GET request with string response:
Multiple filters can be added to the httpClient, in a certain order, forming a chain of filters.
Filters can be used to:
- Alter any request property (headers, url, body, etc...)
- Alter any response property (headers, body, etc...)
- Short-circuit the chain by returning a custom response without proceeding with the HTTP call, allowing for example for client-side caching.
- Intercept some or all calls for debugging/logging purposes
Filters must implement the
Filter interface and implement the
request parameter contains the request (possibly already modified by previous filters) and can be modified by the filter (or ignored)
filterChain parameter represents the chain of filters following the current filter
Filter full example : Transform the response body:
This example transforms the fetched Todos and modify their title
;// Transform Todos : Alter title
Hierarchy of Filters
In 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. The 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.
The hook beforeEach executes before every test.