Serving over HTTP Using Node.js
Understand how to serve a GraphQL API over HTTP using Node.js by exploring best practices including middleware order, handling GET and POST requests, managing query parameters, and delivering JSON responses. Learn how to integrate GraphQL servers with frameworks like Express for seamless client-server communication.
HTTP is the mainstream choice for client-server protocol due to its simplicity. In this lesson, we’ll review a few best practices for setting up a GraphQL server to operate over HTTP.
Web request
Modern web frameworks use a pipeline model where requests are passed through a middleware stack, which are also called filters or plugins. As the request is processed through the framework pipeline, the server can reveal the request sent by the client and transform, override, or close it with a response. Given how the underlying web framework works, GraphQL should ideally be placed after the authentication middleware. This is so it can access our framework’s unique session and our user information in our HTTP endpoint handlers.
URIs and routes
REST is commonly associated ...