#Restful API, #package.json
Sept 26 WIL
rest는 representational state transfer의 약어로, 클라이언트와 서버가 데이터를 서로 주고 받는 스타일의 architecture 형태이다. 기본적으로 rest방식에 6가지 원칙이 있고, 이 원칙을 갖춘 인터페이스를 Restful 이라고 지칭한다.
- client-server
- stateless
- cacheable
- uniform interface
- layered system
- code on demand
Restful API
- API 의 한 종류이다
- URI (=uniform resource identifier)
- uniform 은 리소스 식별하는 통일된 방식
- resource 는 자원, URI로 제한없이 식별한다
- idenfier 는 다른 항목과 구분하고자 할 때 필요한 정보이다
- 현 URI는 resource와 representation으로만 식별한다
- 리소스 표현하려면 명사를 사용한다
- 일관성이 중요하다
- '/' 를 사용하되, 마지막 문자에는 붙지 않는다
- 가독성을 위해 '-'(hyphen) 을 사용한다
- '_'(underscore) 를 사용하지 않는다 오히려, 사용하게 될 경우, 브라우저나 화면에서 혼란만 가져온다
- 소문자를 사용한다
- 파일 확장자를 사용하지 않는다
- CRUD 함수명을 사용하지 않는다
- C : Create (post) R : Read (get) U : Update (put & patch) D : Delete
- URI is indicating for resource, not showing how to act
- requires to use HTTP method
- 필터를 위해 쿼리 파라미터를 사용한다
- ex) array, filtering, paging - no create for new api and use query parameter
package.json
- 프로젝트의 정보와 패키지 버전 정보를 가리키는 파일
- 루트 directory에 위치
- 프로젝트 정보: name, version
- name: consist of one small letter and include with hyphen(-) and underscore(_)
- version: x.x.x version and 작성 규칙을 시맨틱 버저닝이라고 한다
- 패키지 정보: dependencies or devDependencies
- dependencies: required for production environment in applied program
- devDependencies: required for local development and test
- npm 레지스트리에 공개되기 위해 package.json 파일이 필요함
- module 은 node.js 의 require() 함수로 로드될 수 있는 node_modules 그러나, module은 package.json 파일을 가질 필요가 없음