forked from b00tc4mp/isdi-parttime-202403
-
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.
implement delete post and get user name logics in api b00tc4mp#140
- Loading branch information
1 parent
e7e20e5
commit ec82307
Showing
9 changed files
with
330 additions
and
188 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 |
---|---|---|
|
@@ -2,94 +2,27 @@ | |
|
||
```sh | ||
🐖 curl http://localhost:8080/users -v | ||
``` | ||
`` | ||
|
||
- register user | ||
|
||
```sh | ||
🐖 curl -X POST http://localhost:8080/users -H "Content-Type: application/json" -d '{"name":"Pepito","surname":"Grillo","email":"[email protected]","username":"pepitogrillo","password":"123123123","passwordRepeat":"123123123"}' -v | ||
``` | ||
|
||
```js | ||
const xhr = new XMLHttpRequest | ||
|
||
xhr.onload = () => { | ||
debugger | ||
|
||
if (xhr.status === 201) { | ||
console.log('user registered') | ||
|
||
return | ||
} | ||
|
||
const { error, message } = JSON.parse(xhr.response) | ||
|
||
console.error(error, message) | ||
} | ||
|
||
xhr.open('POST', 'http://localhost:8080/users') | ||
|
||
const body = {name:'Peter',surname:'Grillo',email:'[email protected]',username:'pepitogrillo',password:'123123123', passwordRepeat:'123123123'} | ||
|
||
const json = JSON.stringify(body) | ||
|
||
xhr.setRequestHeader('Content-Type', 'application/json') | ||
xhr.send(json) | ||
``` | ||
- authenticate user | ||
|
||
```sh | ||
🐖 curl -X POST http://localhost:8080/users/auth -H "Content-Type: application/json" -d '{"username":"AdrianGon","password":"321321321"}' -v | ||
``` | ||
```js | ||
const xhr = new XMLHttpRequest | ||
|
||
xhr.onload = () => { | ||
debugger | ||
|
||
if (xhr.status === 200) { | ||
console.log('user authenticated') | ||
|
||
return | ||
} | ||
|
||
const { error, message } = JSON.parse(xhr.response) | ||
|
||
console.error(error, message) | ||
} | ||
|
||
xhr.open('POST', 'http://localhost:8080/users/auth') | ||
- get user name | ||
|
||
const body = {username:'pepitogrillo',password:'123123123'} | ||
|
||
const json = JSON.stringify(body) | ||
|
||
xhr.setRequestHeader('Content-Type', 'application/json') | ||
xhr.send(json) | ||
```sh | ||
🐖 curl http://localhost:8080/users/AdrianGon -H "Authorization: Basic AdrianGon" -v | ||
``` | ||
- list posts | ||
|
||
```js | ||
const xhr = new XMLHttpRequest | ||
|
||
xhr.onload = () => { | ||
if (xhr.status === 200) { | ||
const posts = JSON.parse(xhr.response) | ||
|
||
console.log('posts retrived', posts) | ||
|
||
return | ||
} | ||
|
||
const { error, message } = JSON.parse(xhr.response) | ||
|
||
console.error(error, message) | ||
} | ||
|
||
xhr.open('GET', 'http://localhost:8080/posts') | ||
- list posts | ||
|
||
xhr.send() | ||
``` | ||
```sh | ||
🐖 curl http://localhost:8080/posts -v | ||
``` | ||
|
@@ -98,4 +31,10 @@ xhr.send() | |
|
||
```sh | ||
🐖 $ curl -X POST http://localhost:8080/posts -H "Authorization: Basic AdrianGon" -H "Content-Type: application/json" -d '{"title":"Buenos Dias","image":"https://imgs.search.brave.com/J8imP8bduv7lIhsfCsnGwaeKNgdHqp2g5dCpK8aVkYA/rs:fit:860:0:0/g:ce/aHR0cHM6Ly90My5m/dGNkbi5uZXQvanBn/LzAxLzAzLzM2LzA0/LzM2MF9GXzEwMzM2/MDQyNV9IekJxZEkx/d1dOTjBWU3Z2ZXkw/R3RRTlRvaDJLenhy/Ny5qcGc","description":"blah blah"}' -v | ||
``` | ||
|
||
- delete post | ||
|
||
```sh | ||
🐖 $ curl -X DELETE http://localhost:8080/posts/7956804321626201-1716989998980 -H "Authorization: Basic AdrianGon" -v | ||
``` |
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 +1 @@ | ||
[{"author":"jameshook","title":"smile1","image":"https://m.media-amazon.com/images/I/41xsPjrM-pL._AC_UF350,350_QL50_.jpg","description":"hi 2","date":"2024-05-27T14:44:14.236Z","id":"8448820043690848-1716821054237"},{"author":"jameshook","title":"smile2","image":"https://m.media-amazon.com/images/I/41xsPjrM-pL._AC_UF350,350_QL50_.jpg","description":"hi 2","date":"2024-05-27T14:44:21.737Z","id":"05670034285101688-1716821061738"},{"author":"jameshook","title":"smile3","image":"https://m.media-amazon.com/images/I/41xsPjrM-pL._AC_UF350,350_QL50_.jpg","description":"hi 2","date":"2024-05-27T14:44:23.250Z","id":"549161270915079-1716821063251"},{"id":"7049627815708344-1716989932607","author":"AdrianGon","title":"smil3","image":"https://imgs.search.brave.com/rY4vd7ChrTffot87xezWVyJZcsjp10UPNHx2EQMRCfs/rs:fit:860:0:0/g:ce/aHR0cHM6Ly9pLnBp/bmltZy5jb20vb3Jp/Z2luYWxzLzFiL2Qx/L2I2LzFiZDFiNjE1/ZTZkYTcwZGQ3MWRj/ODRmZDJmNDdjODBk/LmpwZw","description":"hi 2","date":"2024-05-29T13:38:52.607Z"},{"id":"11703272214754645-1716989975016","author":"AdrianGon","title":"smil3","image":"https://imgs.search.brave.com/rY4vd7ChrTffot87xezWVyJZcsjp10UPNHx2EQMRCfs/rs:fit:860:0:0/g:ce/aHR0cHM6Ly9pLnBp/bmltZy5jb20vb3Jp/Z2luYWxzLzFiL2Qx/L2I2LzFiZDFiNjE1/ZTZkYTcwZGQ3MWRj/ODRmZDJmNDdjODBk/LmpwZw","description":"hi 2","date":"2024-05-29T13:39:35.015Z"},{"id":"7956804321626201-1716989998965","author":"AdrianGon","title":"smile4","image":"https://imgs.search.brave.com/rY4vd7ChrTffot87xezWVyJZcsjp10UPNHx2EQMRCfs/rs:fit:860:0:0/g:ce/aHR0cHM6Ly9pLnBp/bmltZy5jb20vb3Jp/Z2luYWxzLzFiL2Qx/L2I2LzFiZDFiNjE1/ZTZkYTcwZGQ3MWRj/ODRmZDJmNDdjODBk/LmpwZw","description":"hi 2","date":"2024-05-29T13:39:58.965Z"},{"author":"AdrianGon","title":"Buenos Dias","image":"https://imgs.search.brave.com/J8imP8bduv7lIhsfCsnGwaeKNgdHqp2g5dCpK8aVkYA/rs:fit:860:0:0/g:ce/aHR0cHM6Ly90My5m/dGNkbi5uZXQvanBn/LzAxLzAzLzM2LzA0/LzM2MF9GXzEwMzM2/MDQyNV9IekJxZEkx/d1dOTjBWU3Z2ZXkw/R3RRTlRvaDJLenhy/Ny5qcGc","description":"blah blah","date":"2024-05-29T13:55:28.417Z","id":"7707579376266043-1716990928418"},{"author":"AdrianGon","title":"Buenos Dias","image":"https://imgs.search.brave.com/J8imP8bduv7lIhsfCsnGwaeKNgdHqp2g5dCpK8aVkYA/rs:fit:860:0:0/g:ce/aHR0cHM6Ly90My5m/dGNkbi5uZXQvanBn/LzAxLzAzLzM2LzA0/LzM2MF9GXzEwMzM2/MDQyNV9IekJxZEkx/d1dOTjBWU3Z2ZXkw/R3RRTlRvaDJLenhy/Ny5qcGc","description":"blah blah","date":"2024-05-29T14:01:59.825Z","id":"7741423721689134-1716991319825"},{"author":"AdrianGon","title":"Adrian","image":"https://imgs.search.brave.com/2TUrjrEEig4i0QI4ygiyBBQipd90pfaTC6MV2CYvsjg/rs:fit:500:0:0/g:ce/aHR0cHM6Ly93d3cu/aGFpa3Utb3Mub3Jn/L2RvY3MvdXNlcmd1/aWRlL2VzL2ltYWdl/cy9hcHBzLWltYWdl/cy9kZWJ1Z2dlci5w/bmc","description":"debugger","date":"2024-05-29T14:16:48.728Z","id":"9617450442045541-1716992208729"}] | ||
[{"author":"jameshook","title":"smile1","image":"https://m.media-amazon.com/images/I/41xsPjrM-pL._AC_UF350,350_QL50_.jpg","description":"hi 2","date":"2024-05-27T14:44:14.236Z","id":"8448820043690848-1716821054237"},{"author":"jameshook","title":"smile2","image":"https://m.media-amazon.com/images/I/41xsPjrM-pL._AC_UF350,350_QL50_.jpg","description":"hi 2","date":"2024-05-27T14:44:21.737Z","id":"05670034285101688-1716821061738"},{"author":"jameshook","title":"smile3","image":"https://m.media-amazon.com/images/I/41xsPjrM-pL._AC_UF350,350_QL50_.jpg","description":"hi 2","date":"2024-05-27T14:44:23.250Z","id":"549161270915079-1716821063251"},{"id":"7049627815708344-1716989932607","author":"AdrianGon","title":"smil3","image":"https://imgs.search.brave.com/rY4vd7ChrTffot87xezWVyJZcsjp10UPNHx2EQMRCfs/rs:fit:860:0:0/g:ce/aHR0cHM6Ly9pLnBp/bmltZy5jb20vb3Jp/Z2luYWxzLzFiL2Qx/L2I2LzFiZDFiNjE1/ZTZkYTcwZGQ3MWRj/ODRmZDJmNDdjODBk/LmpwZw","description":"hi 2","date":"2024-05-29T13:38:52.607Z"},{"id":"11703272214754645-1716989975016","author":"AdrianGon","title":"smil3","image":"https://imgs.search.brave.com/rY4vd7ChrTffot87xezWVyJZcsjp10UPNHx2EQMRCfs/rs:fit:860:0:0/g:ce/aHR0cHM6Ly9pLnBp/bmltZy5jb20vb3Jp/Z2luYWxzLzFiL2Qx/L2I2LzFiZDFiNjE1/ZTZkYTcwZGQ3MWRj/ODRmZDJmNDdjODBk/LmpwZw","description":"hi 2","date":"2024-05-29T13:39:35.015Z"},{"id":"7956804321626201-1716989998965","author":"AdrianGon","title":"smile4","image":"https://imgs.search.brave.com/rY4vd7ChrTffot87xezWVyJZcsjp10UPNHx2EQMRCfs/rs:fit:860:0:0/g:ce/aHR0cHM6Ly9pLnBp/bmltZy5jb20vb3Jp/Z2luYWxzLzFiL2Qx/L2I2LzFiZDFiNjE1/ZTZkYTcwZGQ3MWRj/ODRmZDJmNDdjODBk/LmpwZw","description":"hi 2","date":"2024-05-29T13:39:58.965Z"}] |
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
Oops, something went wrong.