티스토리 뷰

Programming

RestAPI

seoca 2019. 1. 10. 13:59

 

 

 

RestAPI

 

REpresentational

State

Transfer

 

 

The most popular types of API is RestAPI. RestAPI makes use of resource-based URL's.

In brief, when we request a server for data but not a normal web page, then servlet will give you a state of the object in XML or JSON format. When you return data, data should have structure and that is the reason why it is in XML/JSON format. What the server is sending is not an object but the state of the object.

Rest API is used to receive that state of the object by using REST API we do CRUD operations.

 

 

 

 

 

 

Status code

200 OK

201 Created

204 No Content

300 Multiple Choice

400 Bad Request

401 Unauthorized Error

404 Not Found

500 Internal Server Error

 

 

Rules

A verb or verb phrase should be used for controller names

A singular noun should be used for document names

A plural noun should be used for collection names

A plural noun should be used for store names

 

 

 

RestAPI 는 웹페이지, 앱 등에서 주소로 요청을 보내고 데이터를 받을 때 사용한다. HTTP가 의도하는 디자인 즉, URI가 정보의 자원을 표현하고 그에 맞는 행위는 Http Method로 표현하는 것을 말하며 이것이 잘 디자인된 API를 RestAPI라고 한다. URI의 의미 중 명사는 resource 동사로는 method를 만든다. 결국 RestAPI 는 architectural style 을 의미하며 그것은 곧 web service를 building하기위한 가이드라인의 집합체라고 할 수 있다. REST는 server-side operation의 작동없이 서버에서 자원을 수정하거나 볼 수 있게 할 수 있다. 

 

 

 

 

Example of RESTful 

 

GET /employees              Read(GETemployees 

GET /employees/3           Read(GET) employees 3

POST /employees            Create(POST) employees

PUT /employees/2           Update(PUT) employees 2

DELETE/employees/1     Delete(DELETE) employees 1

 

 

 

RestAPI 의 장점

  • client 개발자와 server 개발자의 완벽한 분리

  • 객체의 상태를 전송하기 위한 structure로 JSON or XML만 사용한다면 그 어떤 language 나 flatform의 사용이 가능하다

  • message가 message 자체를 설명하기 때문에 client개발자가 resource 를 알아보는 것이 더 쉬워졌다

 

 

 

 

 

Reference

https://www.youtube.com/watch?v=ETdbm5jDDsg

https://www.youtube.com/watch?v=BRdcRFvuqsE

https://stackoverflow.com/questions/27121749/confusion-between-noun-vs-verb-in-rest-urls

https://www.youtube.com/watch?v=qVTAB8Z2VmA

https://www.quora.com/What-is-restful-web-services-Why-we-need-it-How-it-works-I-really-dont-want-definitions-I-like-to-know-about-its-usage-Where-and-Why-Use-case

https://blog.hjf.pe.kr/462

https://blog.mwaysolutions.com/2014/06/05/10-best-practices-for-better-restful-api/

'Programming' 카테고리의 다른 글

Algorithm & Data structure  (0) 2019.01.20
Web app vs Mobile app  (0) 2019.01.20
difference between Framework and Library  (0) 2019.01.11
Servlets  (0) 2019.01.09
static pages and dynamic pages  (0) 2019.01.09