Skip to main content
Version: v2.x

Quickstart RESTified Endpoints

RESTified endpoints allow you to quickly and easily create REST endpoints without writing custom code. This quickstart will walk you through the process of creating a REST endpoint from a GraphQL query.

DOCS E-COMMERCE SAMPLE APP

This quickstart is dependent upon the docs e-commerce sample app. If you haven't already deployed the sample app, you can do so with one click below. If you've already deployed the sample app, simply use your existing project.

Deploy to Hasura Cloud

Step 1: Write a query

From the API tab of the Hasura Console, create a query:

GraphiQL
Query Variables
Request Headers
Documentation Explorer
No Schema Available

After entering the query, click the REST button in the Explorer to configure your endpoint:

Create RESTified Endpoint

Step 2: RESTify it

Enter a name:

single_product_query

Followed by a brief description if you wish:

Retrieve a single product using its id

Next, we'll provide a route that describes the endpoint's purpose and indicates that we wish to accept a query parameter of id for the product:

product/:id

We'll mark GET as the allowed method and finish creating the endpoint by clicking Create.

Create RESTified Endpoint

Step 3: 🍿

To test this endpoint, run the following curl request in your terminal:

curl -H "x-hasura-admin-secret: <YOUR_ADMIN_SECRET>" https://<YOUR_PROJECT_NAME>.hasura.app/api/rest/product/7992fdfa-65b5-11ed-8612-6a8b11ef7372

You should see a response similar to this:

{
"products_by_pk": {
"id": "7992fdfa-65b5-11ed-8612-6a8b11ef7372",
"name": "The Original Tee",
"description": "When you want to keep it simple"
}
}

Recap

What just happened? Well, you just created a REST endpoint without writing a single line of code 🎉

This saves you significant time and effort, as you can convert any query or mutation into a REST endpoint with just a few clicks.

While we created this endpoint from the Console, you can also utilize the API to generate these endpoints for any project.

You have complete control in defining the endpoint, but in this example we followed RESTful best practices to identify the endpoint using product as the pathname and then :id as the argument. Any arguments should match the variables included in the query or mutation, as Hasura expects these values to be passed via the endpoint.

By using RESTified endpoints, you can take advantage of the benefits of both REST and GraphQL, making your Hasura project even more versatile and powerful. For more details, check out the configuration page.