# Migrate from REST to GraphQL

![](/files/-MZwzPfp3ukB1Bj5QZMx)

Only the red text parts are different.

* Repositories
  * REST : <https://github.com/ccapeng/bookstore_api>
  * GraphQL : <https://github.com/ccapeng/bookstore_graphQL>
* Backend differences
  * REST :&#x20;
    * [restframework](/bookstores/topic-rest-to-graphql.md)
    * Implementation of &#x20;

      &#x20; book.apis.py &#x20;

      &#x20; book.serializers.py
    * Middleware cors : bypass the cross site origin.
    * Handle snake-case and camel-case inconsistency.
  * GraphQL :&#x20;
    * [graphene](/bookstores/topic-rest-to-graphql.md)
    * Implementation of &#x20;

      &#x20; book.schema.py
    * Middleware cors : bypass the cross site origin and `OPTIONS` method.
* Frontend differences The difference is only the database query service.
  * REST : Use URL end point.\
    category.js

    ```javascript
      const CategoryService = {
          list: () => {
              let url = "api/category/";
              return Request.get(url);
          }
      }
    ```

    request.js

    ```javascript
      const Request = {

          get: async (url) => {

              try {
                  let result = await axios.get(
                      getFullURL(url),
                      getHeaderConfig()
                  );
                  return Promise.resolve(result.data);
              } catch (error) {
                  console.log(error);
                  return Promise.reject("get error");
              }

          }
      }
    ```
  * GraphQL : Always use `POST` method to submit `query`. category.js

    ```javascript
      const CategoryService = {
          list: async () => {
              let query = `query {
                  categoryList {
                      id
                      name
                  }
              }
              `
              let data = await Request.get(query);
              return data.data.categoryList;
          }
      }
    ```

    request.js

    ```javascript
      const Request = {

          get: async (query) => {

              try {
                  query = query.replace(/^\s+/gm, '');
                  let body = { query }
                  body = JSON.stringify(body);
                  let result = await axios.post(
                      getURL(),
                      body,
                      getHeaderConfig()
                  );
                  return Promise.resolve(result.data);
              } catch (error) {
                  console.log("error list", error);
                  return Promise.reject("get error");
              }

          }
      }
    ```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ccapeng.gitbook.io/bookstores/topic-rest-to-graphql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
