Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yasaricli/tatsy
A simple interface for creating REST APIs
https://github.com/yasaricli/tatsy
api javascript mongodb mongoose rest-api
Last synced: 8 days ago
JSON representation
A simple interface for creating REST APIs
- Host: GitHub
- URL: https://github.com/yasaricli/tatsy
- Owner: yasaricli
- License: mit
- Created: 2019-11-04T15:01:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T00:06:54.000Z (almost 2 years ago)
- Last Synced: 2024-04-17T19:15:32.903Z (7 months ago)
- Topics: api, javascript, mongodb, mongoose, rest-api
- Language: JavaScript
- Homepage:
- Size: 1.19 MB
- Stars: 7
- Watchers: 6
- Forks: 2
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
A simple interface for creating REST APIs
Website | Wiki- [Getting started](#getting-started)
- [Defining Collection Routes](#defining-collection-routes)
- [Defining Custom Routes](#defining-custom-routes)
- [Defining Endpoints](#defining-endpoints)
- [Packages](#packages)
- [Developer Resources](#developer-resources)
- [License](#license)## Getting started
Install with yarn:
yarn add tatsy
or with npm:npm install tatsy
and add a script to your **package.json** like this:
```JSON
"scripts": {
"start": "tatsy --start",
"build": "tatsy --build",
},
```and then just run `yarn start` and go to http://localhost:3000/api
## Defining Collection Routes
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)`.```javascript
// articles.js | Given a URL "/articles/5"
Tatsy.Collection('articles', {
schema: {
title: String,
author: String
}
})
```**`/api/`**
- Operations on the entire collection
- `GET` and `POST`**`/api//:id`**
- Operations on a single entity within the collection
- `GET`, `PUT`, `PATCH` and `DELETE`## Defining Custom Routes
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`.```javascript
// posts.js | Given a URL "/posts/5"
Tatsy.Route({
endpoints: {
get: {
authRequired: true, // default false
action() {
const { _id } = this.urlProps;
return {
_id
}
}
}
}
});
```### Defining Endpoints
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:
- `getAll`
- `get`
- `post`
- `put`
- `delete`## Packages
This repository is a monorepo that we manage using [Lerna](https://github.com/lerna/lerna). That means that we actually publish [several packages](/packages) to npm from the same codebase, including:
| Package | Version | Description |
| ------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| [`tatsy`](/packages/tatsy) | [![npm](https://img.shields.io/npm/v/tatsy.svg?style=flat-square)](https://www.npmjs.com/package/tatsy) | The core of tatsy |
| [`tatsy-http`](/packages/tatsy-http) | [![npm](https://img.shields.io/npm/v/tatsy-http.svg?style=flat-square)](https://www.npmjs.com/package/tatsy-http) | Http Server for Express.js |
| [`tatsy-collection`](/packages/tatsy-collection) | [![npm](https://img.shields.io/npm/v/tatsy-collection.svg?style=flat-square)](https://www.npmjs.com/package/tatsy-collection) | Mongodb collection use mongoose |
| [`tatsy-logger`](/packages/tatsy-logger) | [![npm](https://img.shields.io/npm/v/tatsy-logger.svg?style=flat-square)](https://www.npmjs.com/package/tatsy-logger) | Log using chalk |
| [`tatsy-config`](/packages/tatsy-config) | [![npm](https://img.shields.io/npm/v/tatsy-config.svg?style=flat-square)](https://www.npmjs.com/package/tatsy-config) | Config package |
| [`tatsy-watcher`](/packages/tatsy-watcher) | [![npm](https://img.shields.io/npm/v/tatsy-watcher.svg?style=flat-square)](https://www.npmjs.com/package/tatsy-watcher) | package to watch all javascript files |
## Developer ResourcesInterested in helping or contributing to Tatsy? These resources will help:
* [Core development guide](DEVELOPMENT.md)
* [Contribution guidelines](CONTRIBUTING.md)
* [Issue tracker](https://github.com/tsepeti/tatsy/issues)## License
Tatsy is open source software [licensed as MIT](LICENSE).