generated from cuongndc/ts-npm-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cuong Tran
committed
Oct 8, 2020
1 parent
f9bdf8b
commit 1bde679
Showing
5 changed files
with
60 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
# ts-npm-template | ||
# xuka | ||
|
||
[![Build Status](https://travis-ci.org/103cuong/ts-npm-template.svg?branch=master)](https://travis-ci.org/103cuong/ts-npm-template) | ||
[![Build Status](https://travis-ci.org/103cuong/xuka.svg?branch=master)](https://travis-ci.org/103cuong/xuka) | ||
|
||
A TypeScript template 🌼 for npm package | ||
A simple 👰🏻 HTTP client | ||
|
||
## License | ||
## usage | ||
|
||
```typescript | ||
import { request } from 'xuka'; | ||
|
||
const { data } = await request('https://jsonplaceholder.typicode.com/todos/1'); | ||
``` | ||
|
||
## license | ||
|
||
MIT © [103cuong](https://github.com/103cuong) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
import { request } from '../src'; | ||
|
||
it('test', async() => { | ||
expect(true).toEqual(true); | ||
const { data } = await request('https://jsonplaceholder.typicode.com/todos/1'); | ||
expect(data.userId).toEqual(1); | ||
expect(data.id).toEqual(1); | ||
expect(data.title).toEqual('delectus aut autem'); | ||
expect(data.completed).toEqual(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
import { logger } from 'juno-js'; | ||
import axios, { AxiosRequestConfig } from 'axios'; | ||
|
||
logger().info('Chao xìn 🇻🇳'); | ||
/** | ||
* An HTTP client is implemented from the Axios package. | ||
* | ||
* @param {string} url A url from a network. | ||
* @param {object} options Options to config request. | ||
* See more option here: https://github.com/axios/axios | ||
*/ | ||
const request = (url = '', options: AxiosRequestConfig = {}) => { | ||
const { | ||
method = 'get', responseType = 'json', data = {}, ...config | ||
} = options; | ||
return axios({ | ||
method, | ||
url, | ||
responseType, | ||
data, | ||
...config, | ||
}); | ||
}; | ||
|
||
export { request }; |
Oops, something went wrong.