| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A TypeScript client to support JSON:API specification
npm install @stantanasi/jsonapi-clientimport { model, Schema } from '@stantanasi/jsonapi-client';
export const ArticleSchema = new Schema({
attributes: {
title: {},
},
relationships: {
author: {},
comments: {},
},
});
class Article extends model(ArticleSchema) { }
Article.register('articles')
export default Articleimport { model, Schema } from '@stantanasi/jsonapi-client';
import Comment from './comment.model';
import People from './people.model';
export interface IArticle {
title: string;
author: People;
comments: Comment[];
}
export const ArticleSchema = new Schema<IArticle>({
attributes: {
title: {},
},
relationships: {
author: {},
comments: {},
},
});
class Article extends model(ArticleSchema) { }
Article.register('articles')
export default Articleimport { connect } from '@stantanasi/jsonapi-client'
connect({
baseURL: 'https://example.com',
})
const article = new Article({
title: 'JSON:API paints my bikeshed!',
})
// POST /articles HTTP/1.1
await article.save()
article.id // '1'
// GET /articles HTTP/1.1
await Article.find()
// GET /articles/1 HTTP/1.1
await Article.findById('1')
// GET /articles/1/comments HTTP/1.1
await Article.findById('1').get('comments')
// PATCH /articles/1 HTTP/1.1
await article.save()
// DELETE /articles/1 HTTP/1.1
await article.delete()// GET /articles?include=author.comments HTTP/1.1
await Article.find()
.include({ author: { comments: true } })// GET /articles?fields[articles]=title,author HTTP/1.1
await Article.find()
.fields({
articles: ['title', 'author'],
})// GET /articles?sort=-createdAt HTTP/1.1
await Article.find()
.sort({ createdAt: 'desc' })// GET /articles?page[limit]=10&page[offset]=0 HTTP/1.1
await Article.find()
.limit(10)
.offset(0)// GET /articles?filter[title]=JSON:API%20paints%20my%20bikeshed! HTTP/1.1
await Article.find({
title: 'JSON:API paints my bikeshed!',
})Please refer to the example folder to see how to use it
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
This project is licensed under the Apache-2.0 License - see the LICENSE file for details
© 2025 Lory-Stan TANASI. All rights reserved
| Back | FazBrowse Home | New Git URL |