[TIL] 22.05.31 Rest-API vs GraphQL-API

daniel·2022년 5월 31일
0

[TIL]

목록 보기
4/4
post-thumbnail

What is REST API?

An API, or application programming interface, is a set of rules that define how applications or devices can connect to and communicate with each other. A REST API is an API that conforms to the design principles of the REST, or representational state transfer architectural style. For this reason, REST APIs are sometimes referred to RESTful APIs.

REST api란 란 RESTRepresentational State Transfer 아키텍쳐의 디자인원칙을 따르는 api 이다.

REST는 웹 어플리케이션 상에 존재하는 모든 리소스에 고유한 URI(Uniform Resource Identifier)을 부여합니다. HTTP method(GET, POST, PUT, DELETE 등)를 이용해 리소스 에 대하여 CRUD 명령을 적용합니다.

REST API 구성요소

REST API는 자원(Resource), 행위(Verb), 표현(Representations)의 3가지 요소로 구성된다. URI를 통해 자원을 표시, HTTP Method를 통해 행위하며 , HTTP Message Pay Load를 통해 행위의 응답을 받을 수 있다.


What is GraphQL-API?

GraphQL is a query language (that’s what the “QL” stands for) for APIs and a runtime for fulfilling those queries with your existing data. Basically, it is used to load data from a server to a client -- it’s a way to get data from an API into your application.

GraphQL은 서버 API를 구성하기 위해 만든 데이터베이스 쿼리 언어이다. 쿼리문의 작성이 직관적이며 API를 호출할때 원하는 데이터만 응답 받을수 있다. 이것이 REST와 가장 큰 차이점 중 하나이다.

Rest API의 경우 각각의 요구사항에 대하여 EndPoint를 생성해줘야한다.
하지만 GraphQL의 경우 하나의 Endpoint에서 Resource를 이용하면 클라이언트가 보낸 Query문에 따라 응답이 달라진다.

따라서 Rest와 달리 원하는 정보만 선별적으로 요청할 수 있어 요청-응답을 최적화 할 수 있다.


profile
FE 개발 velog

0개의 댓글