Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
web-api-development/fetches.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
141 lines (130 sloc)
5.52 KB
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
// Articles | |
//bob | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/articles/52', { | |
method: 'PUT', | |
headers: { | |
'Content-type': 'application/json', | |
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImJvYiIsImlhdCI6MTY3NjU1NDYzMH0.Yd-ib9Wito-9oC9Y5jLJtMeEjzAZqRiCmeFmMYjMWxk' | |
}, | |
body: JSON.stringify({title: "test", allText: 'Textual content'}) | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
//alice - admin | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/articles/49', { | |
method: 'PUT', | |
headers: { | |
'Content-type': 'application/json', | |
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsaWNlIiwiaWF0IjoxNjc2MDQyMjM4fQ.NHe2T1WK6JJ2eIxPjUJLqgKxDEDevo4hHxoeM7LyhPE' | |
}, | |
body: JSON.stringify({title: "test", allText: 'Textual content'}) | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/articles', { | |
method: 'POST', | |
headers: { | |
'Content-type': 'application/json' | |
}, | |
body: JSON.stringify({title: "new post", allText: 'content', authorID: 1}) | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/articles', { | |
method: 'GET' | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
//bob | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/articles/48', { | |
method: 'DELETE', | |
headers: { | |
'Content-type': 'application/json', | |
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImJvYiIsImlhdCI6MTY3NjU1NDYzMH0.Yd-ib9Wito-9oC9Y5jLJtMeEjzAZqRiCmeFmMYjMWxk' | |
} | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
//alice - admin | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/articles/48', { | |
method: 'DELETE', | |
headers: { | |
'Content-type': 'application/json', | |
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsaWNlIiwiaWF0IjoxNjc2MDQyMjM4fQ.NHe2T1WK6JJ2eIxPjUJLqgKxDEDevo4hHxoeM7LyhPE' | |
} | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
// Users | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/users', { | |
method: 'POST', | |
headers: { | |
'Content-type': 'application/json' | |
}, | |
body: JSON.stringify({username: "user", email: 'user@name.com', password: 'asd'}) | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/users/1', { | |
method: 'DELETE', | |
headers: { | |
'Content-type': 'application/json', | |
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsaWNlIiwiaWF0IjoxNjc2MDQyMjM4fQ.NHe2T1WK6JJ2eIxPjUJLqgKxDEDevo4hHxoeM7LyhPE' | |
}, | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/users/login', { | |
method: 'POST', | |
headers: { | |
'Content-type': 'application/json' | |
}, | |
body: JSON.stringify({username: "user", password: 'asd'}) | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
// admin role | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/users', { | |
method: 'GET', | |
headers: { | |
'Content-type': 'application/json', | |
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsaWNlIiwiaWF0IjoxNjc2MDQyMjM4fQ.NHe2T1WK6JJ2eIxPjUJLqgKxDEDevo4hHxoeM7LyhPE' | |
} | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
// user role | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/users', { | |
method: 'GET', | |
headers: { | |
'Content-type': 'application/json', | |
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InVzZXIiLCJpYXQiOjE2NzU0NDQ1NzJ9.fY_mVuuxpidoOAzZnARyZFb14RXPa2U8ULS5EYrbcfk' | |
} | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
// JWT | |
// correct credentials | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/users/login', { | |
method: 'POST', | |
headers: { | |
'Content-type': 'application/json' | |
}, | |
body: JSON.stringify({username: "user", password: 'asd'}) | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/articles', { | |
method: 'GET', | |
headers: { | |
'Content-type': 'application/json', | |
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InVzZXIiLCJpYXQiOjE2NzU0NDQ1NzJ9.fY_mVuuxpidoOAzZnARyZFb14RXPa2U8ULS5EYrbcfk' | |
} | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
// incorrect username | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/users/login', { | |
method: 'POST', | |
headers: { | |
'Content-type': 'application/json' | |
}, | |
body: JSON.stringify({username: "eliska", password: 'asd'}) | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) | |
// incorrect password | |
const fetchPromise = fetch('https://kiwipanel-gravitycrater-3000.codio-box.uk/api/v1/users/login', { | |
method: 'POST', | |
headers: { | |
'Content-type': 'application/json' | |
}, | |
body: JSON.stringify({username: "user", password: '123'}) | |
}); | |
fetchPromise.then(res => res.json()).then(res => console.log(res)) |