Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
Added Search handler documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ozziest committed Nov 26, 2023
1 parent 9546b27 commit 6d9bb25
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ const sidebarReference = [
},
{ text: "PATCH", link: "/reference/handlers-patch-handler" },
{ text: "ALL", link: "/reference/handlers-all-handler" },
{ text: "SEARCH", link: "/reference/handlers-search-handler" },
],
},
{
Expand Down
58 changes: 58 additions & 0 deletions docs/reference/handlers-search-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# `SEARCH` Handler

:::warning
By default, it is **disabled**.
:::

You can activate the SEARCH handler to allow HTTP clients to run Elasticsearch-based full-text search queries on the model.

:::warning
Currently, the full-text search feature is **EXPERIMENTAL**.

Still, we strongly suggest to use it in some little parts of your application.
:::

This is a simple definition of the ALL handlers;

```ts
import { Model, DEFAULT_HANDLERS, HandlerTypes } from "axe-api";

class User extends Model {
get handlers() {
return [...DEFAULT_HANDLERS, HandlerTypes.SEARCH];
}
}

export default User;
```

Clients can use the following query to fetch data;

```bash
$ curl \
-H "Content-Type: application/json" \
-X GET http://localhost:3000/api/v1/users/search?text=karl
```

This is an example result of the request;

```json
{
"data": [
{
"id": 1,
"name": "Karl Popper",
"created_at": "2021-10-16T19:18:47.000Z",
"updated_at": "2021-10-16T19:18:47.000Z"
}
],
"pagination": {
"total": 1,
"lastPage": 1,
"perPage": 10,
"currentPage": 1,
"from": 0,
"to": 10
}
}
```

0 comments on commit 6d9bb25

Please sign in to comment.