Skip to content

Commit 768040b

Browse files
author
Caio Almeida
committed
Added example services using axios!
1 parent 05c71b2 commit 768040b

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "React with fetch API Maps - Republica do CEP",
55
"main": "index.js",
66
"dependencies": {
7+
"axios": "^0.18.0",
78
"bootstrap": "^4.3.1",
89
"react": "^16.8.4",
910
"react-dom": "^16.8.4",

src/services/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import axios from 'axios'
2+
3+
const instance = axios.create({
4+
baseURL: 'http://localhost:3003'
5+
})
6+
7+
instance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
8+
9+
const postCreated = (description) => {
10+
return instance({
11+
method: 'post',
12+
data: {
13+
description: description
14+
},
15+
url: '/api/v1'
16+
})
17+
.then(resp => resp)
18+
}
19+
20+
export default {
21+
postCreated
22+
}

0 commit comments

Comments
 (0)