A simple interface for creating REST APIs
Website | Wiki
- Getting started
- Defining Collection Routes
- Defining Custom Routes
- Packages
- Developer Resources
- License
Install with yarn:
yarn add tatsy
or with npm:
npm install tatsy
and add a script to your package.json like this:
"scripts": {
"start": "tatsy --start",
"build": "tatsy --build",
},and then just run yarn start and go to http://localhost:3000/api
One of the most common uses for a REST API is exposing a set of operations on your collections.
All available REST endpoints can be generated for a Mongo Collection using
Tatsy.Collection(name, options).
// articles.js | Given a URL "/articles/5"
Tatsy.Collection('articles', {
schema: {
title: String,
author: String
}
})/api/<collection>
- Operations on the entire collection
GETandPOST
/api/<collection>/:id
- Operations on a single entity within the collection
GET,PUT,PATCHandDELETE
Routes are defined using Tatsy.Route(). A route consists of a path and a set of endpoints
defined at that path.
In this example we have a parameter named _id. If we navigate to the /posts/5 URL in our browser,
inside of the GET endpoint function we can get the actual value of the _id from
(_id) { console.log(_id) }. In this case _id => 5.
// posts.js | Given a URL "/posts/5"
Tatsy.Route({
endpoints: {
get: {
authRequired: true, // default false
action() {
const { _id } = this.urlProps;
return {
_id
}
}
}
}
});The last parameter of Tatsy.Route is an object with properties corresponding to the supported
HTTP methods. At least one method must have an endpoint defined on it. The following endpoints can
be defined in Tatsy:
getAllgetpostputdelete
This repository is a monorepo that we manage using Lerna. That means that we actually publish several packages to npm from the same codebase, including:
| Package | Version | Description |
|---|---|---|
tatsy |
The core of tatsy | |
tatsy-http |
Http Server for Express.js | |
tatsy-collection |
Mongodb collection use mongoose | |
tatsy-logger |
Log using chalk | |
tatsy-config |
Config package | |
tatsy-watcher |
package to watch all javascript files |
Interested in helping or contributing to Tatsy? These resources will help:
Tatsy is open source software licensed as MIT.
