Skip to content

Commit

Permalink
Fix typos & add documentation on README.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
gillchristian committed Nov 9, 2016
1 parent 36140be commit 2d93e8b
Showing 1 changed file with 50 additions and 12 deletions.
62 changes: 50 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
[![bitHound Dev Dependencies](https://www.bithound.io/github/Huemul/trae/badges/devDependencies.svg)](https://www.bithound.io/github/Huemul/trae/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/Huemul/trae/badges/code.svg)](https://www.bithound.io/github/Huemul/trae)


# Install
## Install

```bash
$ npm install --save trae
Expand All @@ -20,25 +19,26 @@ $ npm install --save trae
$ yarn add trae
```

# Usage
```js
import trae from 'trae'
## Basic Usage

// GET: `/api/posts?id=123`
trae.get('/api/posts', { data: { id: 123 } })
A `GET` request to `/api/posts?id=123`:

```js
trae.get('/api/posts', { params: { id: 123 } })
.then((json) => {
console.log(json);
})
.catch((err) => {
console.error(err);
});
```

A `POST` request to `/api/posts`:

// POST: `/api/posts`
```js
trae.post('/api/posts', {
body: {
title: 'My Post',
content: 'My awesome post content...'
}
title: 'My Post',
content: 'My awesome post content...'
})
.then(() => {
console.log('Success!!!');
Expand All @@ -47,3 +47,41 @@ trae.post('/api/posts', {
console.error(err);
});
```

## Trae API


### Request methods

```js
trae.get(url[, config])

trae.delete(url[, config])

trae.head(url[, config])

trae.post(url[, body[, config]])

trae.put(url[, body[, config]])

trae.patch(url[, body[, config]])
```

## Defaults & middleware

### `trae.defaults([config])`

Sets the defaults configuration to use on the requests. This is merged with the default configuration.

```js
trae.defaults({
mode: 'no-cors',
credentials: 'same-origin'
})
```

When call with no param it acts as a getter, returning the configuration.

```js
trae.defaults()
```

0 comments on commit 2d93e8b

Please sign in to comment.