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 table.
To see an alternative method of creating a REST endpoint from an query in the GraphiQL IDE, check out the Create RESTified endpoints page.
Available for Postgres, MS SQL Server, Citus, AlloyDB and CockroachDB databases.
DOCS E-COMMERCE SAMPLE APP
This quickstart/recipe 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.
Step 1: Navigate to the products table.
Data > default > public > products and click the "Create REST Endpoints" button.
Step 2: Choose operations
After clicking on the "Create REST endpoints" button, you will see a modal list of all REST operations (
DELETE) available on the table. Select
CREATE for this demo. Click the
Step 3: View all REST endpoints
You will be able to see the newly created REST endpoints listed in the
API > REST tab.
Step 4: Test the REST endpoint
Click on the
products_by_pk title to get to the details page for that RESTified endpoint. In the "Request
Variables" section for
id enter the value
7992fdfa-65b5-11ed-8612-6a8b11ef7372, the UUID for one of the products
already in the
products table of the docs sample app. Click "Run Request".
You will see the result returned next to the query.
You can test the other
insert_products_one endpoint that we created in the same way by providing a new product
object as the request variable.
You can also use your favourite REST client to test the endpoint. For example, using
curl --location --request GET 'https://<your-hasura-project>.hasura.app/api/rest/products/7992fdfa-65b5-11ed-8612-6a8b11ef7372' \
--header 'Content-Type: application/json' \
--header 'x-hasura-admin-secret: <your-admin-secret>'
What just happened? Well, you just created two REST endpoints for reading a single product and inserting a product, super fast, and without writing a single line of code 🎉
This saves you significant time and effort, as you easily enable REST endpoints on your tables or convert any query or mutation into a REST endpoint with just a few clicks.
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.