0.1.0 • Published 7 months ago

@rster/database-adapter-mongodb v0.1.0

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
7 months ago

Github Shield NPM Shield Documentation TypeDoc

Build Status Contributors Forks Stargazers Issues BSD-3-Clause NPM Downloads Coverage

About The Project

Rster is built to simplify creation of restful backend apis. It is a framework that allows you to build your api in a modular way. It's core framework works quite similar to express, however we provide a few tools like @rster/builder, @rster/database to drastically simplify the creation of your api and directly integrate your database. These tools are especially powerful when combined with typescript as all typings are generated automatically. Also with @rster/generator you can generate a typescript client directly from your server-side api definition which saves you a lot of time and nerves.

NOTE: This project is still in early development and features are added frequently. If you have any suggestions or ideas feel free to open an issue or pull request. @rster/generator and @rster/database are not available via npm yet. They need to be built from source and are not yet documented or tested enough to be used in production. Feel free to try them out and give feedback. Please have some patience, they take a lot of work to build and test. They will be released soon. Thanks!

Built With

typescript nodejs npm eslint jest express

Tutorial Intro

Hello and welcome to the rster project. Rster is the easiest way to build your backend api in nodejs. It is a framework that allows you to build your api in a modular way. Just define your library then use your functions to access and modify your data. Or directly add it to the express app using express.use(). It is up to you. You can even generate a typescript client directly from your server-side api definition!

Let's learn rster rster in less than 5 minutes.

Prerequisites

We recommend you to have basic knowledge of the following tools before starting:

  • node.js: a JavaScript runtime built on Chrome's V8 JavaScript engine.
  • npm: a package manager for the JavaScript programming language.

What you'll need

  • Node.js version 14 or higher (which comes with npm) installed on your computer.
    • When installing Node.js, you are recommended to check all checkboxes related to dependencies.
    • On some systems you might need to install npm separately.

Installation

Install rster package locally

npm install rster

alternatively you can use yarn

yarn add rster

Additional Dependencies

Rster packages a few core dependencies that will help you getting started. However we have a few more dependencies that you might want to install. You definitly want to install a worker implementation. A worker implementation is a package that allows you to run your rster application on a webserver so you can access your api from the internet. We recommend using @rster/worker-express as it is the easiest to get started with.

find more worker implementations here

npm install @rster/worker-express

alternatively you can use yarn

yarn add @rster/worker-express

Getting Started

Lets use express in our application

Firstly we want to import the rest function from rster as well as our worker's implementation. (we'll use express in this example)

import { rest } from "rster";
import "@rster/worker-express";

The worker will extend the prototype of our rest api object. Types are automatically extended as well.

Next we can define the pattern of our api. We will create a simple api that returns a string when we call the /hello endpoint.

const api = rest(function () {
  this.get("/hello", function () {
    this.action(function (req, res) {
      res.status(200).json({ message: "Hello World!" }).end();
    });
  });
});

NOTE: It is important to use the function() syntax instead of the arrow function () => {} as the this keyword is not bound to the arrow function.

Now we can create a webserver using express and pass our api it using the use function and the express worker.

import express from "express";

const app = express();

app.use(api.express());

For more examples, please refer to the Documentation

Roadmap

  • Rster base framework
  • Rster advanced framework
    • Rster builder (in development, heavily worked on right now, will be released soon)
    • Rster database (in development)
    • Rster generator (in development)

See the open issues for a full list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the BSD-3-Clause License. See LICENSE for more information.

Contact

Nicolas Schmidt

twitter github

Project Link: https://github.com/nsc-de/rster

GitHub