Skip to content

Commit e6437a8

Browse files
authored
docs: add code samples APIC-348 (#202)
1 parent ee254f9 commit e6437a8

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

website/docs/gettingStarted.mdx

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: Getting started
3+
---
4+
5+
import Tabs from '@theme/Tabs';
6+
import TabItem from '@theme/TabItem';
7+
8+
<Tabs
9+
groupId="language"
10+
defaultValue="js"
11+
values={[
12+
{ label: 'JavaScript', value: 'js', }
13+
]
14+
}>
15+
<TabItem value="js">
16+
17+
## Installation
18+
19+
To get started, you first need to install `algoliasearch` (or any other available API client package)
20+
21+
```bash
22+
yarn add @experimental-api-clients-automation/algoliasearch
23+
```
24+
25+
Or use a specific package to reduce bundle size:
26+
27+
```bash
28+
yarn add @experimental-api-clients-automation/client-search
29+
```
30+
31+
You can find the full list of available packages [here](https://www.npmjs.com/org/experimental-api-clients-automation).
32+
33+
### Without a package manager
34+
35+
Add the JavaScript to your `<head>`
36+
37+
```html
38+
<script src="https://cdn.jsdelivr.net/npm/@experimental-api-clients-automation/[email protected]/dist/algoliasearch.umd.browser.js"></script>
39+
```
40+
41+
## Using the client
42+
43+
Then you need to import the correct package, depending on your choice:
44+
45+
```js
46+
import { algoliasearch } from 'algoliasearch';
47+
48+
const client = algoliasearch(appId, apiKey);
49+
50+
// And access analytics or personalization client
51+
const analyticsClient = client.initAnalytics(analyticsAppId, analyticsApiKey);
52+
const personalizationCilent = client.initPersonalization(personalizationAppId, personalizationApiKey, 'eu');
53+
```
54+
55+
```js
56+
import { searchApi } from '@algolia/client-search';
57+
58+
const client = searchApi(appId, apiKey);
59+
```
60+
61+
It is possible to customize the client by passing optional parameters:
62+
63+
```js
64+
const client = searchApi(appId, apiKey, {
65+
requester: customRequester(),
66+
hosts: [{
67+
url: 'my.custom.host.net',
68+
accept: 'read',
69+
protocol: 'https',
70+
}]
71+
})
72+
```
73+
74+
Once the client is setup, you can enjoy all of Algolia API !
75+
76+
```js
77+
const res = await client.search({
78+
indexName: 'my-index',
79+
searchParams: { query: 'words to query' },
80+
});
81+
82+
console.log('Search result', res.hits);
83+
```
84+
85+
86+
Or with the `personalization` client
87+
88+
```js
89+
const res = await personalizationCilent.getUserTokenProfile({
90+
userToken: 'token',
91+
});
92+
93+
console.log('User scores', res.scores);
94+
```
95+
96+
</TabItem>
97+
</Tabs>

website/sidebars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const sidebars = {
66
{
77
type: 'category',
88
label: 'Getting Started',
9-
items: ['introduction'],
9+
items: ['introduction', 'gettingStarted'],
1010
},
1111
{
1212
type: 'category',

0 commit comments

Comments
 (0)