/rewyre

A fast and flexible wiring tool for building server side applications in little time, using REST or WebSockets, and built on top of TypeScript decorators.

Primary LanguageTypeScriptMIT LicenseMIT

Rewyre is a fast and flexible wiring tool for developing RESTful and WebSocket APIs using TypeScript decorators.

The rewyre framework is built on top of express, and express-ws and utilises TypeScript and decorators to give you a powerful wiring tool to create API applications in a very short time with built-in support for MySQL/MongoDB for models.


Have a question or suggestion? Join the discord!


Important Changes

See the docs/migrating/v1-v2.md for more information regarding the move to V2.

The framework's version 2 release is now licensed under MIT.


Installation

You can install from NPM with:

npm install --save rewyre

Bootstrap Application

As part of some new changes, I have added a simple bootstrap script, it doesn't do very much other than create a basic application with eslint, and all the required packages, you can use it like:

npx rewyre create-rewyre <foldername/appname>

Getting Started

Below is a simple example showing a database connection and a simple find, for a more in-depth example, have a look at the test folder in the source, which has a simple to-do demo.

Note: The expectation is that this framework is to be used with TypeScript specifically and that you would you use your own tooling for building and compiling it, of course, you can use JavaScript and babel instead, but it is suggested to use TypeScript, for help with setting up, look at the tsconfig.json file inside of the test folder.

// Import the parts we need.
import { Framework, Drivers, Controller, Route, IReturn, Model, AbstractModel, AbstractController } from 'rewyre';


// Define our controller.
@Controller('/', 'home')
class HomeController extends AbstractController {

	@Route('GET', '/')
	public async index(): Promise<IReturn> {
		const users = await this.users.find({});
		return { status: 200, content: users };
	}
}


// Define our model.
@Model('users', 'general', {
	username: 'string',
	password: 'string',
	blocked: 'boolean',
	block_reason: '?string',
})
class UsersModel extends AbstractModel {}


// Create an isolated async function.
(async() => {

	// Create an instance of the framework.
	const application: Framework = new Framework({
		port: 3005,
		database: true,
		databases: [
			{
				unique: 'primary',
				host: 'localhost',
				port: '27017',
				name: 'example-app',
				driver: Drivers.MONGO,
				default: true,
			},
		],
	});

	// Register classes.
	application.register([
		HomeController,
		UsersModel,
	]);

	// Start the server.
	await application.start();
})();

Available Features

The below lists the features and their stable state, this framework's API will not change for the forseable future, any changes will be fully implemented and any non-backwards compatible changes will be in the latest major version, following the semver versioning scheme.

Feature Description Status
HTTP Server The HTTP server is the base for the framework and is built on top of Express. Stable
WebSocket Server The WebSocket server uses express-ws package to apply WebSocket support. Stable
Middleware Support Standard Express middleware is supported using the useMiddleware method. Stable
Static Assets Standard Express static is supported as well using the useStatic method. Stable
Controllers Controller classes and the @Controller decorator are both implemented. Stable
Controller Routes Controller routes are and the @Route decorator are both implemented. Stable
Models Model classes and the @Model decorator are both implemented. Stable
Drivers Database drivers allow you to use one of the many implemented into the framework. Stable
Custom Drivers Define your own database drivers to implement other databases into your framework. Stable
Framework Hooks Allows you to hook functions into internal events. Beta
Plugin Support See documentation but plugins are now implemented to allow you to package code pieces into reusable and shareable components. Beta
Multiple Databases Your models can use any database, including multiple, have data in many databases? Write a model around a specific database instead or just fallback to the default. Beta
Injections Injections are done using a single @Inject decorator and you can inject one or many, you can inject models and providers to any service or controller as required. Stable
Services Service classes and the @Service decorator are both implemented and services can run on a loop based on seconds. Stable
Providers Providers and the @Provide decorator are both implemented, the provider allows you to create built in helper classes that can be injected to controllers, and services. Stable

Upcoming Features

Upcoming features that are planned, some features may come out quicker due to technical requirements.

  • Plugin Support - There is a plan to add plugin support, but I am not sure what this will look like yet.
  • Multiple Databases - Support for using multiple databases using database drivers alongside your own.
  • Model Extend - Allow developers to extend models to add more fields for validation.

Future Plans

The future for this library is big, I have many plans to add lots of new features and more decorators to add additional features, and I plan to turn this (slowly) into a full out-of-the-box TypeScript based framework for building Node.JS server side applications. This framework will be able to handle any structure and can be included into other applications like Vue.JS Server-Side Rendering alongside using it render HTML based applications instead of only API based.