Skip to content

tikiram/typescript-http-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typescript-http-client

Install

npm i https://github.com/tikiram/typescript-http-client#0.3.0
yarn add typescript-http-client@https://github.com/tikiram/typescript-http-client#0.2.0

Example

import {
    ErrorHandlerMiddleware,
    HTTPClient,
    HTTPMethod,
    LoggerMiddleware,
} from 'typescript-http-client';

async function something() {
    const client = new HTTPClient(
        'https://pokeapi.co/api/v2',
        [new LoggerMiddleware(), new ErrorHandlerMiddleware()]
    );

    const response = await client.request<Pokemon>(HTTPMethod.Get, '/pokemon/ditto');

    console.log(response)    
}

Middleware

class SomeLogMiddleware implements Middleware {
  constructor(private readonly seconds: number) {}

  async request(request: Request, next: NextFn): Promise<Response> {
    
    someLog(request)
    
    const response = await next(request);
    
    someLog(request)
    
    return response
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published