Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/parsakafi/vajehyab
VajehYab API client written in JS
https://github.com/parsakafi/vajehyab
api expressjs javascript js json json-api nodejs request vajehyab
Last synced: about 1 month ago
JSON representation
VajehYab API client written in JS
- Host: GitHub
- URL: https://github.com/parsakafi/vajehyab
- Owner: parsakafi
- License: mit
- Created: 2018-04-09T19:13:20.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-10T10:24:39.000Z (over 6 years ago)
- Last Synced: 2024-08-09T15:47:23.914Z (5 months ago)
- Topics: api, expressjs, javascript, js, json, json-api, nodejs, request, vajehyab
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VajehYab
VajehYab API client written in JS## Install
```bash
npm install vajehyab --save
```
Usage
You can get VajehYab API token from [Developer Page](http://api.vajehyab.com/i/developer) ([API Documentation](http://api.vajehyab.com/api/documentation))
```js
const VajehYab = require('vajehyab');
const vajehyabToken = process.env.vajehyabToken; // VajehYab API Token
const client = new VajehYab(vajehyabToken, {ip, product, prettyprint, debug});
```
- `params`
- `token`: VajehYab API token
- `ip`: The User IP. Default is ` `, (Optional)
- `product`: The product name. Default is ` `, (Optional)
- `prettyprint`: The response pretty printed. Default is `true`, (Optional)
- `debug`: The debug mode. Default is `false`, (Optional)
Example
```js
const VajehYab = require('vajehyab');
const vajehyabToken = process.env.vajehyabToken; // VajehYab API Token
const client = new VajehYab(vajehyabToken, {ip:'222.2.65.3', product: 'Test', prettyprint: true, debug: false});
```All method using `async`/`await` in Node >= 8
### Search
This method is used to search for a term or phrase. The meaning of the word is limited and insert "..." at the end.
```js
(async () => {
try {
const search = await client.search(q, {type, start, rows, filter});
console.log(search);
} catch (e) {
console.log(e);
}
})();
```
- `params`
- `q`: The search word
- `type`: The search type, You can set `exact`,`ava`,`like`,`text`. Default is `exact`, (Optional)
- `start`: The start row. Default is `0`, (Optional)
- `rows`: The response rows. Default is `10`, (Optional)
- `filter`: The Database names with priority. Default is `dehkhoda, moein, amid, motaradef, farhangestan, sareh, ganjvajeh, wiki, slang, quran, name, thesis, isfahani, bakhtiari, tehrani, dezfuli, gonabadi, mazani, en2fa, ar2fa, fa2en, fa2ar`, (Optional)
Example
```js
(async () => {
try {
const search = await client.search('رایانه');
console.log(search);
} catch (e) {
console.log(e);
}
})();
```
```js
const search = await client.search('رایانه', {type: 'like', start: 0, rows: 10, filter: 'dehkhoda,moein,amid'});
console.log(search);
```
### Word Detail:This method is used to get the full meaning of a word. It is possible with HTML tags.
```js
const word = await client.word(title, db, num);
```
- `params`
- `title`: The word from search method response
- `db`: The Database name from search method response
- `num`: The `num` parameter from search method response
Example
```js
const word = await client.word('ایران', 'dehkhoda', 1);
console.log(word);
```### Suggest Word:
The proposed list is used for autocomplete.
```js
const suggest = await client.suggest(q);
```
- `params`
- `q`: The search word
Example
```js
const suggest = await client.suggest('ایران');
console.log(suggest);
```### Express Example
```js
const VajehYab = require('vajehyab');
const vajehyabToken = process.env.vajehyabToken; // VajehYab API Token
const client = new VajehYab(vajehyabToken, {ip:'222.2.65.3', product: 'Test', prettyprint: true, debug: false});
const express = require('express');
const app = express();app.get('/', (req, res) => {
(async () => {
try {
const search = await client.search('رایانه');
res.send(search);
} catch (e) {
res.send(e);
}
})();
}).listen(3000);
```