0.1.3 • Published 5 years ago

restful-typeorm v0.1.3

Weekly downloads
8
License
MIT
Repository
github
Last release
5 years ago

RESTful-TypeORM

RESTful-TypeORM is a library for Node to expose CRUD (Create, Retrieve, Update and Delete) operations on TypeORM Entity objects via REST API.

What Problem Does It Solve?

Making available relational data owned and managed by a service to other programs, such as other services or web applications running within a Browser, often involves writing boilerplate code to implement REST primitives to create, update, retrieve and delete data items. This library implements this functionality in a generic manner, utilizing the metadata available within the TypeORM Entities definitions, and hence greatly reduces the amount of code to be written for a typical service. Customization, such as different names of entities and their properties, blocking certain operations, pruning list of returned fields, custom authorization, auditing and other operations are still possible via programmer specified functions.

Features

  • Support for CRUD (Create, Retrieve, Update, Delete) operations by natural mapping of REST operations to DB calls
  • JSON input and output payloads
  • Enahnced Listing of resources (via retrieve of Collection of entities) To be implemented
    • Pagination
    • Ordering
    • Grouping
    • Filtering
    • ...
  • Access of sub-resources (as in Book/id/author where author a property of the Book entity, possibly a foreign-key into Author entity)
  • Behavior customization via declarative means (decorators)
  • Input validation against TypeORM Entity definition
  • Out-of-box embeddings in a CLI and Express server
  • Sample deployments as AWS Elastic BeanStalk and Serverless Lambda
  • CORS support
  • Metadata endpoints to generate Swagger documentations To be implemented
  • Custom authorization and auditing To be implemented

Quick Start Guide

This software is in pre-alpha stage. Not recommended for production use.

To install this package make sure that your machine have a relatively recent version of Node and Yarn installed globally. Then perform following steps:

  • Add restful-typeorm package to your project.
yarn add restful-typeorm
  • To see the software in action on a sample DB schema with SQLite DB, install sqlite package, copy node_modules/examples to your working directory and run the server with environment variable ORMCONFIG_FILE set to the config file.
yarn add sqlite
cp -r node_modules/restful-typeorm/examples .
ORMCONFIG_FILE=./examples/sample1/ormconfig.json yarn rt-server

By default, this server listens at port no. 5000. To use another value, set the environment variable PORT to that value, as in:

PORT=8080 ORMCONFIG_FILE=./examples/sample1/ormconfig.yml yarn rt-server

The SQLite database file location is specified in the configuration file. By default, it is set to .db/sample1.db. You can modify the config. file to use any of the databases supported by TypeORM.

You can now issue curl commands to access the resources:

  • List all books and authors:
curl http://localhost:5000/Book
curl http://localhost:5000/Author

As the DB is empty, the results will show empty lists.

  • Create an Author resource:
curl -X POST -H 'Content-Type: application/json' -d '{"name": "Donald Knuth"}' http://localhost:5000/Author
  • List a specific resource by id:
curl http://localhost:5000/Author/1
  • Update the newly created Author resource:
curl -X PATCH -H 'Content-Type: application/json' -d '{"name": "Donald E. Knuth"}' http://localhost:5000/Author/1
  • Create another Author resource:
curl -X POST -H 'Content-Type: application/json' -d '{"name": "JK Rowling"}' http://localhost:5000/Author
  • List all Author resources:
curl http://localhost:5000/Author
  • Delete an Author resource:
curl -X POST http://localhost:5000/Author/1

User Guide

TBD

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago