A TypeScript client to support JSON:API specification
npm install @stantanasi/jsonapi-client
Create JSON:API model
import { 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 Article
import { model, Schema } from '@stantanasi/jsonapi-client';
import Comment from './comment.model';
import People from './people.model';
export interface IArticle {
id: string;
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 Article
Use methods
import { 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()
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.
- Fork the project
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'feat: add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a pull request
This project is licensed under the Apache-2.0
License - see the LICENSE file for details
© 2025 Lory-Stan TANASI. All rights reserved