forked from b00tc4mp/isdi-bootcamp-202405
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87e1ef9
commit e275c2a
Showing
17 changed files
with
123 additions
and
23 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import express from 'express' | ||
import findUser from './data/findUser.js' | ||
|
||
const app = express() | ||
|
||
app.use(express.json()) | ||
|
||
app.get('/users/:username', (req, res) => { | ||
const username = req.params.username | ||
|
||
try{ | ||
const user = findUser(user => user.username === username) | ||
if(!user){ | ||
return res.status(404).send('user not found') | ||
} | ||
res.json(user) | ||
} catch(error){ | ||
res.status(500).send(error.message) | ||
} | ||
}) | ||
|
||
app.listen(8080, () => console.log('server running at http://localhost:8080/users/{username}')) | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import express from 'express' | ||
import findPost from './data/findPost.js' | ||
|
||
const app = express() //es la instancia de express que se usará para definir rutas y middleware | ||
|
||
app.use(express.json()) //le dice a la aplicación que use el middleware 'express.json()' para parsear las peticiones | ||
|
||
app.get('/posts/:postId', (req, res) => { //se define una ruta GET en el endpoint '/posts/:postId | ||
const postId = req.params.postId //extrae el valor del parámetro de la URL 'postId' | ||
|
||
try{ | ||
const post = findPost(post => post.id === postId) | ||
if(!post){ | ||
return res.status(404).send('post not found') | ||
} | ||
res.json(post) | ||
} catch(error){ | ||
res.status(500).send(error.message) | ||
} | ||
}) | ||
|
||
app.listen(8080, () => console.log('server running at http://localhost:8080/posts/{postId}')) //el sevidor comienza a esuchar en el puerto 8080 |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import express from 'express' //importamos el módulo express | ||
|
||
const api = express() //creamos una instancia de express y la guardamos en la constante api | ||
|
||
api.get('/hello', (req, res) => { //efinimos una ruta HTTP GET en '/hello' | ||
|
||
res.send('Hello, world') | ||
|
||
//req: request, contiene información sobre la solicitud HTTP | ||
//res: response, objeto de respuesta que se usa para enviar una respuesta al cliente | ||
|
||
}) | ||
|
||
api.listen(8080, () => console.log('server up')) | ||
|
||
//iniciamos el servidor para que escuche en el puerto 8080 |
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
curl -X GET http://localhost:8080/posts/onlstpoafkw |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
curl -X POST 'http://localhost:8080/users/julitoCamelas ' |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
curl http://localhost:8080/hello -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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
curl -X POST jttp://localhost:8080/posts -H 'Content-Type: application/json' -d '[ | ||
{ | ||
"image": "https://media.giphy.com/media/g5R9dok94mrIvplmZd/giphy.gif?cid=790b7611t0zs44n98uqyevqcf7813v2y1by0mmk3mejeu6mw&ep=v1_gifs_trending&rid=giphy.gif&ct=g", | ||
"author": "maxPower", | ||
"id": "onlstpoafkw", | ||
"date": "2024-07-12T09:04:37.515Z", | ||
"caption": "yay", | ||
"likes": [], | ||
"follows": [], | ||
"favs": [] | ||
}, | ||
{ | ||
"image": "https://media.giphy.com/media/mLZ6kvGkH31z0BAKUX/giphy.gif?cid=790b7611t0zs44n98uqyevqcf7813v2y1by0mmk3mejeu6mw&ep=v1_gifs_trending&rid=giphy.gif&ct=g", | ||
"author": "cauliFlower", | ||
"id": "2cxgeu12zsw0", | ||
"date": "2024-07-12T09:03:37.515Z", | ||
"caption": "oh", | ||
"likes": [], | ||
"follows": [], | ||
"favs": [] | ||
}, | ||
{ | ||
"image": "https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExdDB6czQ0bjk4dXF5ZXZxY2Y3ODEzdjJ5MWJ5MG1tazNtZWpldTZtdyZlcD12MV9naWZzX3RyZW5kaW5nJmN0PWc/2bJWG8k0HAktq/giphy.gif", | ||
"author": "julitoCamelas", | ||
"id": "3fswobxum9q0", | ||
"date": "2024-07-12T09:03:50.515Z", | ||
"caption": "hey", | ||
"likes": [], | ||
"follows": [], | ||
"favs": [] | ||
}, | ||
{ | ||
"id": "ce4fdb4238o", | ||
"image": "https//nlknvliver", | ||
"caption": "yass", | ||
"author": "cauliFlower", | ||
"date": "2024-07-12T09:01:57.515Z", | ||
"likes": [], | ||
"follows": [], | ||
"favs": [] | ||
} | ||
]' |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
curl -X POST http://localhost:8080/users -H 'Content-Type: application/json' -d '[{"name":"Julito","surname":"Camelas","email":"[email protected]","username":"julitoCamelas","password":"julito123","post":"https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExdDB6czQ0bjk4dXF5ZXZxY2Y3ODEzdjJ5MWJ5MG1tazNtZWpldTZtdyZlcD12MV9naWZzX3RyZW5kaW5nJmN0PWc/2bJWG8k0HAktq/giphy.gif","following":[],"favs":[]},{"name":"Cauli","surname":"Flower","email":"[email protected]","username":"cauliFlower","password":"cauliflower4","post":"https://media.giphy.com/media/mLZ6kvGkH31z0BAKUX/giphy.gif?cid=790b7611t0zs44n98uqyevqcf7813v2y1by0mmk3mejeu6mw&ep=v1_gifs_trending&rid=giphy.gif&ct=g","following":[],"favs":[]},{"name":"Max","surname":"Power","email":"[email protected]","username":"maxPower","password":"maxpower1","post":"https://media.giphy.com/media/g5R9dok94mrIvplmZd/giphy.gif?cid=790b7611t0zs44n98uqyevqcf7813v2y1by0mmk3mejeu6mw&ep=v1_gifs_trending&rid=giphy.gif&ct=g","following":[],"favs":[]},{"name":"janfry","surname":"topera","email":"[email protected]","username":"janfryTopera","password":"janfrytopera1","favs":[],"following":[],"avatar":"https://c8.alamy.com/comp/2EDB67T/cute-horse-avatar-cute-farm-animal-hand-drawn-illustration-isolated-vector-illustration-2EDB67T.jpg"}]' |
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