How to create data using the REST API

Previous post demonstrated creating a serverless function to login using the REST API.

As discussed earlier, RESTful APIs provide authentication and CRUD functionalities. They conform to the constraints of the REST architectural style and allow interaction with RESTful web services.
If you are new to the world of APIs, you may check this post to know the differences between REST API and Web API.

Anyway, let’s move on to creation of data using the REST API.

  • Data can be created using the POST method. Two different endpoints can be used.

1./rest/v1
2./rest/v1/fn/mutation/upsert - equivalent to calling the Hypi upsert function in GraphQL

  • The body (--data-raw) contains the data to be inserted in the table.
  • The format of the input data is the same as normal create operation.

Here are the sample cURL requests. The only differentiating point between two requests is the use of different endpoints.

Sample 1

curl --location --request POST 'https://api.staging.hypi.dev/rest/v1' \
--header 'hypi-domain: inclemency.apps.hypi.app' \
--header 'content-type: application/json' \
--header 'authorization: your_auth_key' \
--data-raw '{ 
    "values": {
      "StudentMedicalRecord": [
        { "height": 5.5, "weight": 60, "bloodGroup": "B+"}
       ]
    }
}'

Sample 2

curl --location --request POST 'https://api.staging.hypi.dev/rest/v1/fn/mutation/upsert' \
--header 'hypi-domain: inclemency.apps.hypi.app' \
--header 'content-type: application/json' \
--header 'authorization: your_auth_key' \
--data-raw '{ 
    "values": {
      "StudentMedicalRecord": [
        { "height": 5.5, "weight": 60, "bloodGroup": "B+"}
       ]
    }
}'

***Replace hypi-domain, authorization, and input data with your own set of values.

Check the Create Data with POST requests POSTMAN collection for the data creation requests in different programming languages! Click </> and choose the programming language of your choice.

Run in Postman