mirror of
https://github.com/karust/openserp.git
synced 2026-08-17 05:46:07 +08:00
Add OpenSERP SDK usage examples
This commit is contained in:
11
examples/quickstart/js-basic-search/README.md
Normal file
11
examples/quickstart/js-basic-search/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Basic search (JavaScript)
|
||||
|
||||
Runs one Google search with `@openserp/sdk` and prints the titles and URLs.
|
||||
|
||||
```bash
|
||||
npm install
|
||||
node index.js
|
||||
```
|
||||
|
||||
Edit the `text`, `engine`, or `limit` in [index.js](index.js) to change the search.
|
||||
To use the hosted API instead of a local server, follow the commented line at the top of the file.
|
||||
18
examples/quickstart/js-basic-search/index.js
Normal file
18
examples/quickstart/js-basic-search/index.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { OpenSERP } from "@openserp/sdk";
|
||||
|
||||
// Hosted API instead? Get a key at https://openserp.org/dashboard/keys:
|
||||
// const client = new OpenSERP({ apiKey: "<YOUR_API_TOKEN>" });
|
||||
const client = new OpenSERP({ baseUrl: "http://localhost:7000" });
|
||||
|
||||
const { results } = await client.search({
|
||||
engine: "google",
|
||||
text: "open source search api",
|
||||
region: "US",
|
||||
lang: "EN",
|
||||
limit: 10,
|
||||
});
|
||||
|
||||
for (const item of results) {
|
||||
console.log(`${item.rank}. ${item.title}`);
|
||||
console.log(` ${item.url}`);
|
||||
}
|
||||
14
examples/quickstart/js-basic-search/package.json
Normal file
14
examples/quickstart/js-basic-search/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "openserp-example-js-basic-search",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"dependencies": {
|
||||
"@openserp/sdk": "^0.2.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user