REST
는 Resource의 형태와 요청 방법이 하나로 연결되어 있다.GraphQL
은 Resource의 형태와 요청 방법이 완전히 분리되어 있다.REST
/books/1
{
"title" : "Romeo and Juliet",
"author" : {
"name" : "william shakespeare",
"nation" : "UK",
"birth" : 1564
}
}
type Book {
id: ID
title: String
author: Author
}
type Author {
id: ID
name: String
birth: Int
books: [Book]
}
type Query {
book(id: ID!): Book
author(id: ID!): Author
}
/graphql?query={ book(id: "1") { title, author { name } } }
{
"title": "Romeo and Juliet",
"author": {
"name": "william shakespeare",
}
}
REST와 다르게 GraphQL은 하나의 엔드포인트에 접근한다.