Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arfedulov/json-api-url-parser
Parse jsonapi complient urls
https://github.com/arfedulov/json-api-url-parser
Last synced: 16 days ago
JSON representation
Parse jsonapi complient urls
- Host: GitHub
- URL: https://github.com/arfedulov/json-api-url-parser
- Owner: arfedulov
- Created: 2019-10-29T03:27:52.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T00:43:09.000Z (about 2 years ago)
- Last Synced: 2024-11-18T10:57:04.211Z (about 2 months ago)
- Language: TypeScript
- Size: 289 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# json-api-url-parser
Parse jsonapi complient urls [specs](https://jsonapi.org/format/).
```ts
import { parse } from '@arfedulov/json-api-url-parser';/** Parsed url parameters ( including those from url query string ). */
export interface JsonApiUrlParams {
resourceType: string;
resourceId?: string;
relationshipType?: string;
pageNumber?: number;
pageSize?: number;
filters?: Filter[];
sort?: Sort[];
}export interface Filter {
/** Field name to apply filtering to. */
fieldName: string;
/** A predicate expressed in textual form ( this module is unaware of semantics ). */
predicateString: string;
}export interface Sort {
/** Field name to apply sorting to. */
fieldName: string;
/** Sorting order. */
order: Order;
}/**
* Sorting order.
*
* `+` Means "ascending"
* `-` Means "descending"
*/
export type Order = '+' | '-';const parsed: JsonApiUrlParams = parse('https://abc.com/articles/12345/relationships/author?sort=-createdAt,title&page[number]=5&page[size]=10');
console.log(parsed);
/*
{ resourceType: 'articles',
resourceId: '12345',
relationshipType: 'author',
filters: undefined,
sort:
[ { fieldName: 'createdAt', order: '-' },
{ fieldName: 'title', order: '+' } ],
pageNumber: 5,
pageSize: 10 }
*/
```