Skip to content
This repository was archived by the owner on Jul 12, 2025. It is now read-only.

Repository files navigation

Springpress

A Top-level framework of Express.js for developing clean architecture API service, especially on TypeScript.

Springpress provides basic Express.js functions and MVC utilities related out of the box. Let you deep-dive into the world of OOP and the scent of our motivation, Spring Boot with Springpress.

Installation

Node.js 16.15.0 (LTS) is required

Using npm:

$ npm install springpress

Using yarn:

$ yarn add springpress

Usage

Assume you are creating a dog controller that sends a response of the dog's name when requesting to /dog/name.

Server

First, you need to create a main class that extends Springpress class. This class will store all of your things. e.g. services, controllers, repositories initialization.

import{Springpress}from'springpress';classExampleServerextendsSpringpress{publiconStartup(): Promise<void>{// This code will run when your start your application.// All of initialization should do it here.}}

Don't forget to call Springpress#listen to bind to and to listen for conections. This method returns an http.Server object (the built-in HTTP module). You can use this instance in your testing framework to work with HTTP.

constport=3000;// you can specify whatever port you want :)constexampleServer=newExampleServer(port);exampleServer.listen();

Controller

Controller Mapping

Easily define your controller with @ControllerMapping decorator:

@ControllerMapping('/dog')// <-- Decorator here!classDogControllerextendsController{// Routes implementation will be here.}

The @ControllerMapping decorator will mount your class on a router with the path where you specified in the first decorator parameter. In this case, this class will be mapped with /dog on the router.

  • A client can connect by http://localhost:3000/dog/ followed by your implemented route. (port 3000 is just an example)
  • On this step, you will not actually be able to access it. You need to implement a route first by following the next step.

Route Mapping

Easily define your route with @RouteMapping decorator:

@ControllerMapping('/dog')classDogControllerextendsController{
@RouteMapping('/name',Methods.GET)// <-- Decorator here!privateasyncgetName(req: Request,res: Response){res.status(200).json({name: 'Doge',});}}

The @RouteMapping decorator will mount your decorated method as a routing destination of an HTTP request in a controller.

A RouteMapping parameter

  • path - a string of route path
    • It can be anything that Express.js routing support
  • method - an enum of HTTP method (You can use Methods imported from Springpress)

Now, your client will see http://localhost:3000/dog/name and get a response like below in a JSON format.

{
"name": "Doge"
}

Controller Registration

Everything above in the Controller section will not work if you haven't registered the controller in the Server class.

import{Springpress}from'springpress';import{DogController}from'./controllers/DogController';classExampleServerextendsSpringpress{publiconStartup(): Promise<void>{// Don't forget here!constcontrollerRegistry=this.getControllerRegistry();controllerRegistry.register(newDogController());}}

Contribution

There are many ways in which you can participate in this project, for example:

License

Copyright (c) Vectier. All rights reserved.

Licensed under the MIT license.

About

Writing Express but feel like Spring Boot

Topics

Resources

Code of conduct

Security policy

Stars

8 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages