# @car-co-uk/api-client

> Allows asynchronous requests to Car.co.uk REST API and get results with native Promise or async/await.

Latest version **0.0.1** (published 2020-04-02) · 0 weekly downloads

## Install

```sh
npm install @car-co-uk/api-client
pnpm add @car-co-uk/api-client
yarn add @car-co-uk/api-client
bun add @car-co-uk/api-client
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2020-04-02 |
| First published | 2020-04-02 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 33.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | lgh06 |

## Links

- npm: https://www.npmjs.com/package/@car-co-uk/api-client
- npm.io page: https://npm.io/package/@car-co-uk/api-client

## Dependencies (4)

- [@bugsnag/js](https://npm.io/package/@bugsnag/js.md) ^6.5.0
- [cross-fetch](https://npm.io/package/cross-fetch.md) ^3.0.0
- [query-string](https://npm.io/package/query-string.md) ^6.2.0
- [@bugsnag/plugin-react](https://npm.io/package/@bugsnag/plugin-react.md) ^6.5.0

## Recent versions

- 0.0.1 (latest) — 2020-04-02

## README

# Car.co.uk API client library

Allows asynchronous requests to Car.co.uk REST API and get results with native Promise or async/await.

## Initialize

```javascript
import APIClient from '@car-co-uk/api-client';

const api = new APIClient({
  apiUrl: 'https://website.com/api/v1',
  apiToken: '<token>'
});
```

## Usage

```javascript
// fetch all auctions with await
const auctionsResponse = await api.auctions.list();
const auctions = auctionsResponse.json;
for(const car of auctions){
  console.log(car.name)
}

// fetch all auctions with Promise
api.auctions.list().then(({status, json}) => {
    const auctions = json;
    for(const car of auctions){
      console.log(car.name)
    }
});

// create a car
api.auctions.create({ name: 'My Awesome Auction' }).then(({status, json}) => {
    const carId = json.id;
});
```

##  Error Handling

```javascript
// with await
try {
  const createResult = await api.auctions.create({ name: 'My Awesome Auction' });
  const newcar = createResult.json;
} catch(e) {
  console.log(e);
}

// with Promise
api.auctions.create({ name: 'My Awesome Auction' })
.then(({status, json}) => {
  if(status === 200) {
    // success
    const newcar = json;
  } else {
    // 404 or bad request
  }
})
.catch(err => {
  console.log(err)
});
```

## Methods

* `api.authorize(baseUrl, user, pass)`

---
_Source: https://npm.io/package/@car-co-uk/api-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
