관리 메뉴

Silver Library (Archived)

[1] REST API, and JS syntax. 본문

Face the fear, build the future/Laboratory

[1] REST API, and JS syntax.

Chesed Kim 2021. 10. 20. 20:20
반응형

개요.

재시도 하기에 앞서, 개념 때문에 막히는 부분이 없도록 다시한번 확실하게 알아두고 싶었습니다.

 

필요 준비물:

REST API, CRUD, JS syntax 에 대한 이해. fetch.

 

메모 1:

express 와 node.js 는 실전에서 거의 확실시 사용된다고 보여집니다.

다만 백엔드에서 담당하는 API 구축과 혼동되지 않도록 조심하되, 지금은 REST API 에 집중할 필요.

 

메모 2:

res, req 를 사용해서, aws 에 생성되어 있는 API를 읽어와서 이를 출력하는 것이 목표로 보여짐.

이 과정 중에서, 마크업을 이용해서 문제에서 요구하는 파일에서 렌더링 후, 각기 호출하는 식으로 설계가 요구되어 보임.

 

개인 기록:

당시 시간제한이 거슬려서 이것저것 못해 봤는데, 다시 알고 읽어보니 생각보다 불가능하지 않을 것 같다는 의견.

아마도 다음 달 중으로 구현 해 볼 수 있을 듯. 다만, 이게 헷깔린다.

 

1) AWS 의 고양이 사진 API 호출 (이건 이제 괜찮은데)

2) node 에 내부의 directory API 호출 (이게 문제)

- directory 부분은 node 와 연결 해야 할 것으로 사료됨(간략히 보았을 때 기준).

- main(사진이 렌더링 되어야 할 곳), app, api, component 4개.

여기서 breadcrumb 는 navigation 을 돕는 컴포넌트 이름.

- 게다가 이를 활용해서 폴더 클릭을 설계하는 점이 있음.

- isRoot 는 정말 이진 트리에서 나오는 그 것 인가? 그렇다면 그 node의 자료 구조 개념으로서 접근하기.

간략 설계 및 목표:

1. 특정 링크 클릭 시, 고양이 사진을 해당 페이지에서 출력 하도록 해야함.

2. upper directory 클릭 시, 특정 directory list 를 출력 하도록 해야함.

3. breadcrumb 로 navigation 기능을 구현.

 

일단 여기까지.

 

좀 더 알아보는 메모: [2 - Node.js 에서 HTTP 클라이언트와 서버 구현, 3 - fetch, 4 - ES6 module]

[1]

"app.get(route,requestHandler) is the syntex for http request. In your case "usersController.getById" function is actually a request handler. Any request handler will have (req,res) parameter in this specific order."


Is "result" the name of the returned value or is it a convention that JS developper use? By that I mean, does this for example work?

From my experience, yes - result is often used. Often times you'll see thing like value, response, but ultimately it can be whatever you define. I would recommend sticking to convention, and also check out the MDN Promise tutorial if you are starting out with understanding NodeJS asynchronous operations.

Also for req, res variables what does this mean?

app.get("/users/:userId", [ usersController.getById ]);

That is a middleware chain. Check out the Express docs for more information.

the getById method defined in the controller needs (req, res), does that mean, when i call it like the code above, the req and res arguments are implicitly used? Also it needs a parameter :

req.params.userId

which is in the url It won't work if I change the param name right? for example:

req.params.id

Yes, that is using a named parameter. Without the full router code, it is hard to know how the getById method is linked to the defined route. The Express routing documentation will likely be a good start on that.


참고 영상:

앞 부분만 재확인 ~30:00

참고 링크:

JS 전개 구문 (spread syntax)

 

전개 구문 - JavaScript | MDN

전개 구문을 사용하면 배열이나 문자열과 같이 반복 가능한 문자를 0개 이상의 인수 (함수로 호출할 경우) 또는 요소 (배열 리터럴의 경우)로 확장하여, 0개 이상의 키-값의 쌍으로 객체로 확장시

developer.mozilla.org

 

[JavaScript] 자바스크립트 전개 구문(spread syntax) 이해하기

전개 구문(Spread Syntax)란? 전개 구문(Spread Syntax)는 ECMAScript6(2015)에서 새로 추가된 문법으로 간단하게 이 문법은 문법 이름 그대로 객체 혹은 배열들을 펼칠 수 있게 해 준다. 문법 // 펼칠 대상이..

bigtop.tistory.com