Video Description
Of the many new features added to Hasura 2.0 – adding REST endpoints to stored queries and mutations has to be a standout. You can hardly finish typing “GraphQL” into a search engine before the “GraphQL vs REST”, “Is GraphQL going to replace REST” punditry floods the suggested query autocomplete.
The fact is, was, and was bound to alway be, REST is not going to go anywhere. There’s a number of compelling use-cases where REST is still a preferred method for fetching data over the wire.
REST and GraphQL
The question should always be “when” to use which API specification. If you are building for embedded systems, it’s by far easier to modify the resolver than it is to modify the query. If you are building for the Jamstack, ensuring protected execution of your content is critical. With REST, you get many of these benefits by default.
Fortunately, with REST support in Hasura, you can have both. To create a REST endpoint from a query or mutation, you first create a named query/mutation in the GraphiQL API explorer, then press the REST button in the GraphiQL interface. From there, provide a helpful name to identify your endpoint later, provide the suffix path for where there endpoint should be called, and choose which verb (GET, POST, PATCH, PUT, DELETE) your endpoint should respond to.
Hasura supports traditional body parsing for dynamic variables as well as dynamic URL segments. Dynamic URL segments are denoted with : as a prefix in the path. Calling /shapes/round to a URL defined as /shapes/:shape would yield in a body of {"shape": "round"} being passed to the query or mutation serving as the resolver.
Whether the project you are building is a better target for REST or you have a legacy project you are planning on migrating slowly to GraphQL, REST endpoints in Hasura allow you to support the best of both worlds with sacrificing the developer velocity you’ve come to expect from Hasura and Hasura Cloud.
Learn more in this deep dive where we cover REST endpoints and a quick introduction to access controls to go with it.
-----
🚀 Hasura makes your data instantly accessible over a real-time GraphQL API, so you can build and ship modern apps and APIs faster. Hasura connects to your databases, REST servers, GraphQL servers and third party APIs (eg: Stripe, Salesforce) to provide a unified realtime GraphQL API across all your data sources instantly.
Check out our features:
https://hasura.ioFind us on Twitter:
https://twitter.com/HasuraHQJoin our community:
https://hasura.io/discord-----