skip to Main Content

i want to call weather Api and i have little bit concept of graphQl and restApi.I can not decide which api is suitable to hit request on server.why we use GraphQl,webhook when rest api makes easy to call the api.

Before this i already work on restapi that is easy to manage and give me whole details of request.Now i want to work with graphQl for weather Api.

2

Answers


  1. The difference is that they are not comparable.

    REST is a Representational State Transfer (software architectural style).

    API is an Application Programming Interface.

    GraphQL is a query language for your API, and a server-side runtime for executing queries using a type system you define for your data.

    That is, Query language for your API is not the same as Application Programming Interface for Representational State Transfer.

    P.S.
    Moreover, you did not report anything on the merits of the matter.
    You did not give any incorrect examples of your own that would lead you into a hopeless situation. (stack overflow).

    Login or Signup to reply.
  2. Both REST and GraphQL are APIs (Application Programming Interfaces) used to fetch and manipulate data over the internet, but they have different principles and structures.

    In REST, you typically fetch data from a specific URL:

    GET /users/12345  <--- to get user details
    GET /users/12345/posts  <--- to get posts by that user
    

    On the other hand, in GraphQL you specify exactly what data you need in a single query, regardless of the resources involved. This avoids over-fetching and under-fetching of data.

    {
      user(id: 12345) {
        name
        posts {
          title
        }
      }
    }
    

    Some of the key diffs:

    Versioning:

    • REST offers a good versioning strategy if there are major changes in you code. (e.g., v1, v2).
    • GraphQL usually doesn’t offer versioning, instead you would just updated your schema.

    Error Handling

    • In REST you handle errors by returning specific HTTP Status Codes,
      to indicate various types of errors (eg. 400, 500)
    • GraphQL typically returns a 200 OK status even if there’s an error,
      but errors are provided in the response body – you return a response that includes the "errors" field, an array of one or more error objects.

    They both have pros and cons, and the right tool depends on the specific needs of the project. Generally speaking, REST is still widely used and may be simpler for some applications, while GraphQL is more suitable in complex systems where flexibility and data efficiency are paramount.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search