REST APIs provide an effective means of interacting with your Orama Cloud index.
The REST APIs allow you to update, insert, and remove data from your index seamlessly. The system then queues these changes until you request a new deployment.
This guide will show you how to use the REST APIs data source, to deploy and manage your indexes on Orama Cloud.
Creating an index
Firstly, create a new index using “REST API” as a data source. You’ll find it under “custom integrations”.
Insert a name and optionally add a description for your index, then click on “Create index”.
After creating it, you will need to define the searchable properties schema.
Define the schema
For this guide, we will use a very simple schema, which consists of two simple properties: "name" (of type string) and "age" (of type number).
Automatic embeddings generation are included in your index, to perform vector and hybrid search on it. By default, all the string properties are included in the embeddings generation.
After we complete this step, we can save the configuration by clicking on “Save”.
This will bring us to the following screen, where we can find some instructions on how to deploy and update an index via REST APIs.
From here, you can use the Official SDKs to manage your index data.
Generate a Private API Key
To use the REST APIs, you will need to generate a private API key. You can do this in the developer tools section of the dashboard.
Developer ToolsAccess the Orama Cloud dashboard section to manage your Private API Keys.
Simply add a new private key by clicking on Generate API Key and providing a name and an optional description for it. A single private API key can be used to manage multiple indexes.
Managing your index
Now that you have created an index, you can start managing it using the REST APIs. Here is a list of the available methods.
You can integrate with the REST APIs using the Official SDKs or by making direct HTTP requests.
The official SDKs supported languages are JavaScript, Swift, Kotlin, PHP, and Python. In the following examples, we will also include a cURL example.
Inserting a snapshot
A snapshot is a complete override of a given index. It means you bulk upload a number of documents, which entirely substitute the live index all at once.
For example, if you want your live index to only contain the two following documents:
You can use the snapshot API to bulk update the live index:
While the snapshot API is convenient for replacing a live index with a new one, there may be instances where you only want to change some documents, inserting, updating, and deleting ones.
This is where the notify API becomes really convenient.
Let”s say you want to add a new document:
you can use the notify API to put that operation in queue for the next deployment:
As you can see, you”ll need to pass an array of objects to an upsert operation (which will do that based on the id field). If Orama finds that document, it will update it; otherwise, it will insert a new one.
You can also remove an existing document using the remove operation. For example, this is how you can remove the document with id "2":
After you have inserted a snapshot or put a number of insert, remove, or update operations in the queue, you have to deploy a new version of the index.
This will trigger a new deployment and will make the new index available worldwide in just a few minutes.
Clearing the index data
Sometimes, you may want to re-insert all the documents in the index and to do that, you will first need to tell Orama to clear the index for the next deployment.
You can do that by using the clear API, or by creating an empty snapshot:
This will clear the index, making the next deployment start from empty status. You can then notify some operations to update the index. This ensures that old data is not present in the index anymore.
Check for pending operations
If you lost track of the operatiosn you ran via the SDK or APIs, you can always check if there are pending operations in the queue by using the hasPendingOperations API:
Now that you have your index deployed, you can start using it in your application's frontend.
You can install a ready-to-use Web Component to your site, like the Search Box, which is framework agnostic and can be used in any JavaScript environment.
You can also install the JavaScript SDK to build your own searching experience.
UI ComponentsAdd a fully featured and highly customizable Search Box component in your application.
JavaScript SDKLearn how to use your Orama Cloud index in a JavaScript application.
React ExampleLearn how to use your Orama Cloud index in a React application.
Vue ExampleLearn how to use your Orama Cloud index in a Vue application.