parent
388bf4a194
commit
1e6b265bd8
@ -1,2 +1,4 @@
|
|||||||
let linkService = new LinkService();
|
let linkService = new LinkService();
|
||||||
linkService.getLinks();
|
linkService.getLinks();
|
||||||
|
let api = new ApiService()
|
||||||
|
api.get(2)
|
@ -0,0 +1,32 @@
|
|||||||
|
class ApiService{
|
||||||
|
constructor(){}
|
||||||
|
async get(id){
|
||||||
|
const baseUrl = `https://jsonplaceholder.typicode.com/posts/${id}`;//edit
|
||||||
|
const headers = {
|
||||||
|
method: 'GET'
|
||||||
|
};
|
||||||
|
let response = await fetch(baseUrl, headers);
|
||||||
|
let responseJson = await response.json()
|
||||||
|
console.log(responseJson)
|
||||||
|
|
||||||
|
}
|
||||||
|
async post(){
|
||||||
|
const baseUrl = `https://jsonplaceholder.typicode.com/posts/`;//edit
|
||||||
|
const headers = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
word:"yessss"
|
||||||
|
})
|
||||||
|
};
|
||||||
|
fetch(baseUrl, headers).then( (response) => {
|
||||||
|
if (response.ok)
|
||||||
|
console.log("Posted")
|
||||||
|
else
|
||||||
|
throw new Error('Une erreur est survenue durant l\'appel HTTP.');
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue