CS/Web
REST API (REpresentational State Transfer)
daylee de vel
2021. 6. 22. 15:42
기계들의 대화법, http 를 이용한 통신규칙
웹에서 남의 컴퓨터를 실행시킨다.
내용을 가져오고 추가, 수정도 가능
URI: 인터넷 자원(리소스, 데이터)을 나타내는 고유 식별자 (ID: identifier)
- 식별하기 위한 이름이므로 고유해야함 one and only!
- 리소스: 웹에 존재하는 이미지, 동영상, DB 자원
Resource 의 구성
- Collection: 복수형 topic's', 그룹으로 된 전체 데이터
- Element: 개별 row 하나의 데이터
URL, URN (Uniformed Resource Name) ⊂ URI
- URI(Uniform Resource Identifier): 인터넷 상의 자원을 식별하기 위한 문자열의 구성으로, URI는 URL을 포함하는 큰 개념
- URL(Uniform Resource Locator): 인터넷 상 자원의 위치, 결국 어떤 파일의 위치, Path를 의미. 일반적으로 사이트 도메인을 자주 의미함.
- URN (Uniformed Resource Name): 자원의 이름
CRUD (method): 정보 가공방법
- Create: POST - 본래 생성을 위해 준비된 기능 - collection, element 단위로 가져옴
- Read: GET - 읽기
- Update: PUT - 전체 / PATCH 부분 수정
- Delete: DELETE - 삭제
Rule 규칙
- URI: Noun
URI is a resource, written in a noun form.
`` `GET /members/show/1 (x)GET /members/1 (o)` ``
- Use the HTTP Verbs
GET: read
POST: create new info
PUT: update all
PATCH: update including index
DELETE: delete including index - Use Specific Pattern of Routes/Endpoint URLs
lowercase only
no hyphen '-', only underscore '_'
no file extension e.g. .jon, .xml - 데이터 타입을 규정하지 않음: json, xml 등 사용할 수 있음
- 결과를 알려줄 때는 status code (2xx, 4xx) 등을 사용한다
최근 트렌드
ARN: AWS(Amazon Web Service) Cloud 에서 Resource를 지정할 때 URN을 확장한 ARN 사용
e.g.
arn:aws:kms:ap-northeast-2:888869365995:key/679f76c9-a93d-4144-8163-9319e9d9cd18
aws 클라우드의, kms 서비스이고, ap-northeast-2(서울) 지역의, 888869365995 사용자의, key/679f76c9-a93d-4144-8163-9319e9d9cd18 리소스를 가리킴
이전 포스트 참고:
https://velog.io/@daylee/TIL-Python-Basics-Day-66-Building-Your-Own-API-with-RESTful-Routing
출처:
https://www.youtube.com/watch?v=PmY3dWcCxXI
https://blog.lael.be/post/61
https://programming119.tistory.com/194