Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moqada/simple-api-client
Simple API Client for JavaScript
https://github.com/moqada/simple-api-client
Last synced: 3 days ago
JSON representation
Simple API Client for JavaScript
- Host: GitHub
- URL: https://github.com/moqada/simple-api-client
- Owner: moqada
- License: mit
- Created: 2016-04-30T17:33:05.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T23:40:44.000Z (7 months ago)
- Last Synced: 2024-09-18T16:56:32.346Z (about 2 months ago)
- Language: JavaScript
- Size: 430 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# simple-api-client
[![Greenkeeper badge](https://badges.greenkeeper.io/moqada/simple-api-client.svg)](https://greenkeeper.io/)
[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Coverage Status][codecov-image]][codecov-url]
[![Dependency Status][daviddm-image]][daviddm-url]
[![DevDependency Status][daviddm-dev-image]][daviddm-dev-url]
[![License][license-image]][license-url]Simple API Client for JavaScript.
***WIP***
## Installation
```
npm install --save @moqada/simple-api-client
```## Usage
### JavaScript
```javascript
import SimpleAPIClient from '@moqada/simple-api-client';class APIClinet extends SimpleAPIClient {
constructor({token, custom}: {token: string, custom: string}) {
super({endpoint: 'http://api.example.com/v1'});
this.token = token;
this.custom = custom;
}getDefaultOptions(): Object {
return {
headers: {
'Authorization': `Bearer ${this.token}`,
'X-Custom-Header': `${this.custom}`
}
};
}toResponse(error: ?Object, response: ?Object): Object {
if (error) {
return {error};
}
return {
body: response.body
};
}getUsers(query): Promise<{body: Object}, {error: Object}> {
return this.get('/users', {query});
}
}const clinet = new APIClinet({token: 'xxxxxxxyyyyy', custom: 'foobar'});
client.getUsers({offset: 20, limit: 10}).then(({body}) => {
console.log(body);
}).catch(({error}) => {
console.error(error);
}):
```### TypeScript
A import style is different from JavaScript.
```typescript
import {SimpleAPIClient} from '@moqada/simple-api-client';
```## Todo
- [ ] Test
- [x] Support TypeScript (experimental)## Related
- [@moqada/simple-api-client-generator](https://github.com/moqada/simple-api-client-generator) - A CLI generating API Client from JSON Hyper Schema
[npm-url]: https://www.npmjs.com/package/@moqada/simple-api-client
[npm-image]: https://img.shields.io/npm/v/@moqada/simple-api-client.svg?style=flat-square
[travis-url]: https://travis-ci.org/moqada/simple-api-client
[travis-image]: https://img.shields.io/travis/moqada/simple-api-client.svg?style=flat-square
[daviddm-url]: https://david-dm.org/moqada/simple-api-client
[daviddm-image]: https://img.shields.io/david/moqada/simple-api-client.svg?style=flat-square
[daviddm-dev-url]: https://david-dm.org/moqada/simple-api-client#info=devDependencies
[daviddm-dev-image]: https://img.shields.io/david/dev/moqada/simple-api-client.svg?style=flat-square
[codecov-url]: https://codecov.io/github/moqada/simple-api-client
[codecov-image]: https://img.shields.io/codecov/c/github/moqada/simple-api-client.svg?style=flat-square
[license-url]: http://opensource.org/licenses/MIT
[license-image]: https://img.shields.io/github/license/moqada/simple-api-client?style=flat-square