TIL029_210426

JIYOONยท2021๋…„ 4์›” 26์ผ
0

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
29/42
post-thumbnail

๐ŸŠ ๊ฐ์ƒ

๐Ÿ“™ ์—ดํ’ˆํƒ€ ์ฝ”๋”ฉ ์‹œ๊ฐ„ 4hour
๐Ÿ‘๐Ÿผ -
๐Ÿ‘Ž๐Ÿผ -

๐Ÿš€ ๋ชฉํ‘œ

  • Udemy์—์„œ Javascript ๊ฐ•์ขŒ ์ˆ˜๊ฐ•ํ•˜๊ธฐ (424/682)
  • ๊ฐœ์ธ ํ”„๋กœ์ ํŠธ ์ง„ํ–‰

๐Ÿ“ฃ The Web Developer Bootcamp 2021

35. Defining RESTful Routes

353. Parsing the request body

app.use(express.urlencoded({ extended: true }));
app.use(express.json());

app.get('/tacos', (req, res) => {
  res.send('get /tacos response');
});
app.post('/tacos', (req, res) => {
  console.log(req.body);
  const { meat, qty } = req.body;
  res.send(`ok here are your ${qty} ${meat} tacos`);
});

whether the data is sent through a form or through postman, we will have data potentially in our post request body and in express
easy way to access the data -> query string data
post request -> include a property called req.body

req.body -> contains key value pairs of data submitted in the request body. By default, it is undefined and it's populated(์ •๋ณด๊ฐ€ ์ž๋™์œผ๋กœ ์ฑ„์›Œ์ง) when you use body-parsing middleware such as express.json or express.urlencoded
html์ด๋‚˜ json ๋“ฑ ๋‹ค์–‘ํ•œ ํ˜•ํƒœ๋กœ ๋“ค์–ด์˜ค๋Š” ์ •๋ณด๋“ค์„ express์—์„œ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ง€ ๊ฒฐ์ •ํ•ด์•ผ ํ•จ
๊ทธ๋ž˜์„œ ์ด๋Ÿฌํ•œ ์ •๋ณด๋“ค์„ ์–ด๋–ป๊ฒŒ parseํ•  ์ง€ express์—๊ฒŒ ์•Œ๋ ค์ค˜์•ผ ํ•จ, to parse form-encoded information from the request body
->app.use(express.urlencoded({ extended: true }));
app.use : running some code or some function on every single request doesn't matter what the pathe name is, what type of request is(get,post)

-> ๊ทธ๋Ÿฌ๋‚˜ ์ด๊ฒƒ๋งŒ์œผ๋กœ๋Š” json file์„ parsinggํ•˜์ง€ ๋ชป ํ•จ

app.use(express.json());
-> built-in middleware function, it parses incoming requests with json payloads(์ „์†ก๋˜๋Š” ๋ฐ์ดํ„ฐ)

354. Intro to REST

representational state transfer

an architecural style for distributed hypermedia systems
Basically a set of guidelines for how a client + server should communicate and perform CRUD operations on a given resource

REST - idea, guideline, standards or principles

The main idea of REST is treating data on the server-side as resources than can be CRUDed. The most common way of approaching REST is in formatting the URLs and HTTP verbs in your applicaitons.

CRUD - create, read, update, delete or destroy

-> how can I go about implementing different routes to allow a user to perform CRUD on that resource(entity, tweet, or user or image or text message, mean anything -> expose or provide access to via HTTP)

355. RESTful comments overview

GET / comments - list all comments
POST / comments - create a new comment
GET / comments/:id - get one comment (using ID)
PATCH / comments/:id - update one comment
DELETE / comments.:id - destroy one comment

356. RESTful comments index

์ฐธ๊ณ ๋งํฌ: ์–„ํŒํ•œ ์ฝ”๋”ฉ์‚ฌ์ „

npm init -> package.json
npm i ejs -> node.modules
mkdir views public public/partials

https://www.reddit.com/r/dogecoin/comments/mrsx8e/hey_guys_i_just_became_a_dogecoin_millionaire/
hey_guys_i_just_became_a_dogecoin_millionaire -> slug, ์•ž์˜ ์•„์ด๋””๋งŒ์œผ๋กœ๋„ ํŽ˜์ด์ง€ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ์‚ฌ์šฉ์ž๊ฐ€ ๋ถ๋งˆํฌ๋‚˜ ๊ณต์œ ํ•  ๋•Œ ๋” ์•Œ๊ธฐ ์‰ฝ๋„๋ก ํ•˜๋Š” ๊ฒƒ
https://www.reddit.com/r/dogecoin/comments/myu51i/this_is_sad_news_please_do_take_a_moment_of/gvx89g8/ -> post id ๋’ค์— comment id๋„ ์žˆ๋‹ค ์ด๋ฅผ nested route๋ผ๊ณ  ํ•จ

2๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2021๋…„ 8์›” 7์ผ

We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. https://wmbet.casino/

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ
comment-user-thumbnail
2021๋…„ 8์›” 11์ผ

Remarkable article, it is particularly useful! I quietly began in this, and I'm becoming more acquainted with it better! Delights, keep doing more and extra impressive! thc concentrates for sale

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ