https://github.com/0xjohnnyboy/spider-query-builder
Builds a queryparams string for interactions with API Platform based backend
https://github.com/0xjohnnyboy/spider-query-builder
angular api-platform api-rest javascript query-builder queryparams typescript typescript-library
Last synced: 4 months ago
JSON representation
Builds a queryparams string for interactions with API Platform based backend
- Host: GitHub
- URL: https://github.com/0xjohnnyboy/spider-query-builder
- Owner: 0xJohnnyboy
- License: agpl-3.0
- Created: 2021-10-15T14:38:24.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-12-09T14:55:09.000Z (about 3 years ago)
- Last Synced: 2025-08-16T07:35:51.799Z (4 months ago)
- Topics: angular, api-platform, api-rest, javascript, query-builder, queryparams, typescript, typescript-library
- Language: TypeScript
- Homepage:
- Size: 246 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
```
_ _ _ _ _ _
(_) | | | | (_| | | |
___ _ __ _ __| | ___ _ __ __ _ _ _ ___ _ __ _ _| |__ _ _ _| | __| | ___ _ __
/ __| '_ \| |/ _` |/ _ | '__ / _` | | | |/ _ | '__| | | | '_ \| | | | | |/ _` |/ _ | '__|
\__ | |_) | | (_| | __| | | (_| | |_| | __| | | |_| | |_) | |_| | | | (_| | __| |
|___| .__/|_|\__,_|\___|_| \__, |\__,_|\___|_| \__, |_.__/ \__,_|_|_|\__,_|\___|_|
| | | | __/
|_| |_| |___/
```
[]()
[]()


# Installation
```bash
$ npm i @sonicfury/spider-query-builder
```
# What it does
This typescript library is designed to help you interact between your front end app and your backend based on API Platform. It can
help you build your query from a filters form with typing etc.
# License
This project is under AGPL 3 License
[See license](LICENSE)
# How to
[See docs](docs/docs.md)
## Example
Say you have a DomainService (`domain.service.ts` file) with the something like:
```typescript
class DomainService extends AbstractService{
getDomain(query: string): Observable> {
const url = `${this.baseUrl}/domain?${query}`;
return this.http.get(url);
}
}
```
API Platform has specific semantics for the built-in filters.
With this library, you have to build `SpiderParams` for each filter, like:
```typescript
import {SpdrQueryBuilder} from "./SpdrQueryBuilder";
const qb = new SpdrQueryBuilder(); // initialize the builder
qb
.exists('username', true) // wether the property 'username' exists
.search('firstname', ['john']) // search for a 'john' firstname
.search('lastname', ['doe']) // search for a 'doe' lastname
.range('rank', 1, 200); // search for a result with rank between 1 and 200
this.domainService.getDomain(qb.query)
.subscribe(
// ...
)
```
`qb.query` will be formatted as `exists[username]=true&firstname=john&lastname=doe&rank[between]=1..200`;
# Issues
Feel free to submit an issue if you find something wrong or if you feel some important feature is missing. Be sure to note the version you're using, and provide minimum context and information (as if you were on SO).
# Contributing
You're welcome to contribute if you want. Just be sure to check [the guidelines](CONTRIBUTING.md)