Welcome to hyper ⚡️. Let's create a simple ExpressJS REST API that leverages the hyper connect SDK to add and retrieve documents to the hyper data service.
As you complete this tutorial you will learn how to:
Here's a high-level sequence diagram of what we will build:
Our API provides a consistent shape across all our services, making it easy to learn. For example, adding something to a service feels the same across different service types:
A hyper application represents an application within hyper cloud. Each hyper application is owned by either a user account or a team. A hyper application contains key pairs used to access its application services, such as Data, Storage, Cache, Queue, and Search. Creating a hyper app provides the primary mechanism for controlling which of your client apps can access the resources protected by the hyper cloud.
Now, let's create a hyper application.
Once created, you will see the new app in your list of applications.
Selecting a hyper app from the Applications page will display the application and a series of tabs. The Keys tab contains your App Keys.
An app key consists of a Key, Secret, and associated Connection String. An app key allows hyper to uniquely identify your app. Our ExpressJS API will need an app key when negotiating access to the resources protected by hyper cloud. A hyper cloud connection string consists of a key, secret, hyper cloud server, and hyper app name:
cloud://<key>:<secret>@cloud.hyper.io/<hyper application name>
Use the copy button to copy the connection string to your clipboard. The real secret will be copied even if it is redacted in the user interface.
In a future step, we will provide the connection string value to the hyper connect SDK.
Once you have the code open within your IDE, let's install dependencies
Open the server.js file which defines the ExpressJS API. Here you will find three endpoints:
Our goal is to complete the callback functions for the GET /docs and POST /docs endpoints.
Open api/add-doc-to-data-svc.js. This file provides the callback function for the POST /docs endpoint. Add the following code:
In your editor, open the api/get-doc-from-data-svc.js. This file provides the callback function for the GET/docs/:id endpoint. It will retrieve a document given the document id provided in the path. Add the following code:
At this point, we have created two API endpoints to handle adding and retrieving a JSON document to and from a data service within your hyper app.
Let's add some documents:
Now let's retrieve the documents: