URL and Routes
- URL stands for Uniform Resource Identifiers, which are strings of characters used to identify resources on the web.
- They consist of two main parts: the protocol (e.g., http:// or https://) and the resource’s location (For Example: ., www.w3wiki.org).
- Routes, on the other hand, are paths defined within a web application that map incoming requests to specific handlers or controllers responsible for processing those requests.
- For example, in a web application for an online store, the route “/products” might be used to display a list of products, while the route “/cart” might be used to manage the shopping cart.
- Now, in case of GraphQL applications, graphql server operates on a single URL of the API endpoint to perform all database operations. This URL is “/graphql” for most cases, however, developers can change the route as per their need.
- In GraphQL, data is organized as an entity graph, which means each piece of data is connected to others in a network, unlike in REST where data is accessed via URLs.
Serving GraphQL over HTTP
HTTP or Hypertext Transfer Protocol, is the foundation of Web communication. Being a stateless protocol, each request from a client to the server is independent and doesn’t retain information about past requests. GraphQL is a query language for APIs and a runtime for executing those queries.
Unlike traditional REST APIs with fixed endpoints and predefined structures, GraphQL allows clients to request the specific data they need on the same endpoint.
One common way to serve GraphQL is over HTTP, providing an efficient and flexible means of communication between client and server. In this article, we’ll explore how we can use the HTTP protocol to serve GraphQL and how it differs from traditional RESTful approaches.