4.1.1 • Published 2 months ago

@smg-automotive/api-client-pkg v4.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

api-client-pkg

CircleCI semantic-release

Usage

npm install @smg-automotive/api-client-pkg

Configuration

The available instance methods are listed below. The specified config will be merged with the instance config.

ApiClient.configure({
  baseUrl: 'https://api.automotive.ch/api',
  headers: { 'Content-Type': 'application/json' },
})

Instance methods

The ApiClient provides promise-based methods for GET, POST, PUT and DELETE.

Typing

You can define the request and the response type of your method as follows:

interface Car {
  make: string
  horsepower: number
}

// data has type Car
var data = await ApiClient.get<Car>('/listings/search')

// data has type { id: string } and body is typed as Car
var data = await ApiClient.post<{ id: string }, Car>('/listings/create',
  { make: 'bmw', horsepower: 300 },)

Parameters

If your request URL contains parameters, you can use curly brackets and the ApiClient replaces it with the passed data.

// fetch is called with baseUrl/dealers/123/listings/456
await ApiClient.get < string > ('dealers/{dealerId}/listings/{listingId}', {
  params: { dealerId: 123, listingId: 456 },
})

Authorization

You can pass in accessToken to the request options if you are talking to a protected API. The client will automatically set the header with a Bearer token.

Error handling

Testing

Development

npm run build

You can link your local npm package to integrate it with any local project:

cd smg-automotive-example-pkg
npm run build

cd <project directory>
npm link ../smg-automotive-example-pkg

Release a new version

New versions are released on the ci using semantic-release as soon as you merge into master. Please make sure your merge commit message adheres to the corresponding conventions.

4.1.1

3 months ago

4.1.0

8 months ago

4.0.2

1 year ago

3.6.0

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

3.5.0

1 year ago

3.4.0

1 year ago

3.3.1

1 year ago

3.2.1

2 years ago

3.2.0

2 years ago

3.3.0

1 year ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago