Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Tools to implement JSON API, such as, end point, query params, body params, validation and transformation response.

Notifications You must be signed in to change notification settings

klerick/nestjs-json-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Smart Tools for NestJS

A comprehensive monorepo of NestJS libraries for building standardized APIs with JSON:API and JSON-RPC 2.0 specifications, with fine-grained access control and resource permissions.


πŸ“š Table of Contents


🎯 Overview

This monorepo provides a complete set of tools to simplify the development of server and client applications using NestJS. It includes support for two popular API protocols and a powerful access control system:

API Protocols:

  • JSON:API – Build RESTful APIs with standardized request/response formats
  • JSON-RPC 2.0 – Implement remote procedure calls using JSON

Access Control:

  • CASL – Fine-grained access control with full integration for JSON:API resources

All packages are designed to work seamlessly with modern ORMs like TypeORM and MikroORM, and include built-in support for PGlite for local development.


πŸ“‹ Prerequisites

  • Node.js >= 20.0.0
  • npm or yarn

πŸ“¦ Packages

1. JSON:API

Build production-ready JSON:API compliant REST APIs with automatic CRUD generation, filtering, sorting, pagination, and relationship handling.

Package Description
json-api-nestjs Core library for creating JSON:API compliant servers. Automatically generates endpoints for CRUD operations, relationships, filtering, sorting, pagination, and atomic operations. Supports TypeORM and MikroORM adapters.
json-api-nestjs-typeorm TypeORM adapter for json-api-nestjs. Enables JSON:API functionality with TypeORM entities, migrations, and repositories.
json-api-nestjs-microorm MikroORM adapter for json-api-nestjs. Provides JSON:API support with MikroORM entities, migrations, and advanced query features.
json-api-nestjs-sdk Type-safe client SDK for consuming JSON:API endpoints. Works with Axios, Fetch API, and Angular HttpClient. Supports filtering, sorting, includes, atomic operations, and provides full TypeScript type inference.

2. JSON-RPC

Implement JSON-RPC 2.0 servers and clients with support for HTTP and WebSocket transports, batch requests, and automatic method discovery.

Package Description
nestjs-json-rpc JSON-RPC 2.0 server implementation for NestJS. Supports HTTP and WebSocket transports, batch requests, custom error handling, and automatic method registration via decorators.
nestjs-json-rpc-sdk Type-safe JSON-RPC client SDK with automatic method inference, batch request support, and WebSocket/HTTP transport options.

3. Access Control (ACL)

Add fine-grained Access Control Lists to your JSON:API endpoints using CASL with template-based rule materialization.

Package Description
nestjs-acl-permissions Type-safe ACL module with CASL integration for JSON:API endpoints. Features template interpolation, field-level permissions, context-based rules, lazy evaluation, and transparent ORM-level filtering. Can be used standalone or with automatic integration via json-api-nestjs.

πŸš€ Quick Start

Installation

This monorepo uses Nx and supports TypeORM and MikroORM with PGlite for local development.

# Install dependencies
npm install

Setup TypeORM Database

# Initialize database and run migrations
npm run typeorm:up:remove  # Removes existing DB and runs migrations

# Or just run migrations (if DB exists)
npm run typeorm:up

# Seed the database
npm run typeorm:seeder

Setup MikroORM Database

# Initialize database and run migrations
npm run microorm:up:remove  # Removes existing DB and runs migrations

# Or just run migrations (if DB exists)
npm run microorm:up

# Seed the database
npm run microorm:seeder

Running Demo Applications

JSON:API Server (TypeORM)

# Using npm script
npm run demo:json-api

# Or using nx directly
nx run json-api-server:serve-typeorm

Server will start on http://localhost:3000 (or configured port)

Available endpoints:

  • GET /api/users - List all users
  • GET /api/users/:id - Get single user
  • POST /api/users - Create user
  • PATCH /api/users/:id - Update user
  • DELETE /api/users/:id - Delete user
  • GET /api/users/:id/relationships/:rel - Get relationships
  • And more...

JSON:API Server (MikroORM)

# Using nx
nx run json-api-server:serve-microorm

🌟 Features

  • Automatic CRUD Generation – Generate complete REST APIs from ORM entities
  • JSON:API Compliant – Full specification support including relationships, filtering, sorting, pagination, sparse fieldsets
  • Atomic Operations – Perform multiple operations in a single request
  • Type Safety – Full TypeScript support with type inference
  • Multiple ORMs – Support for TypeORM and MikroORM
  • JSON-RPC 2.0 – Implement RPC servers with HTTP/WebSocket transports
  • Access Control – Fine-grained permissions with CASL integration
  • Swagger/OpenAPI – Automatic API documentation generation
  • Extensible – Override default controllers and services

πŸ“– Documentation

Each package has detailed documentation in its own README:


πŸ“˜ Examples & Usage

For detailed usage examples and real-world scenarios, refer to the comprehensive E2E test suites. These tests serve as living documentation and demonstrate best practices:

JSON:API SDK Examples

Learn how to use the JSON:API client SDK with various operations:

JSON-RPC Examples

Explore JSON-RPC 2.0 client usage patterns:

Access Control (ACL) Examples

Understand fine-grained permission enforcement with CASL integration:

Each test file includes detailed JSDoc comments explaining the scenarios, ACL rules, and expected behavior.


🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


πŸ“ License

This project is MIT licensed.


Made with ❀️ by Aleksandr Kharkovey

About

Tools to implement JSON API, such as, end point, query params, body params, validation and transformation response.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages