The generated API clients are a work in progress, you can also find our stable clients on the Algolia documentation.

Skip to main content

Usage

warning

The amount of changes in this new version is significant. If you are upgrading for v4, you should thoroughly test your application before deploying to production.

Installation

To get started, you first need to install algoliasearch (or any other available API client package).

All of our clients comes with type definition, and are available for both browser and node environments.

yarn add algoliasearch@beta
# or
npm install algoliasearch@beta

Or use a specific package:

yarn add @algolia/client-search@beta
# or
npm install @algolia/client-search@beta

Without a package manager

Add the following JavaScript snippet to the <head> of your website:

<script src="https://cdn.jsdelivr.net/npm/algoliasearch@beta/dist/algoliasearch.umd.min.js"></script>

Example

You can now import the Algolia API client in your project and play with it.

import { searchClient } from '@algolia/client-search';

const client = searchClient('YOUR_APP_ID', 'YOUR_API_KEY');

// Add a new record to your Algolia index
const response = await client.saveObject({
indexName: '<YOUR_INDEX_NAME>',
body: { objectID: 'id', test: 'val' },
});

// use typed response
console.log(response);

// Poll the task status to know when it has been indexed
await client.waitForTask({ indexName: '<YOUR_INDEX_NAME>', taskID: response.taskID });

// Fetch search results, with typo tolerance
const response = await client.search({
requests: [
{
indexName: '<YOUR_INDEX_NAME>',
query: '<YOUR_QUERY>',
hitsPerPage: 50,
},
],
});

// use typed response
console.log(response);

Advanced use cases

If you don’t find a use case that suits your needs, please request it.

You can learn more on how to use Algolia in your project by reading our dedicated guides for advanced use cases.