Powter
Give power to your Router!
Purpose
Powter was created with the purpose of creating more readable code, and easier testing. It provides nice documentation of your API as a side effect.
I wanted to make Powter as lightweight as possible. Swagger's express middleware solves alot of problems I had with express, but it is quite heavy and has quite a few strange quirks.
What is it?
Powter is a simple abstraction on top of the express router module that makes your code more testable and straight forward, while also providing some basic documentation.
The examples below show the simplicity attained with some basic configuration
With Powter:
{ // Handle Request} { // Handle Request}
Without Powter:
router = router router
Testing
Testing was a large motivation beind building Powter. Without powter, you cannot truly write unit tests because you are also testing express. Not to mention that if you are using a library like supertest, you are most likely testing your server startup file as well.
The below examples show you the difference of using powter vs normal express definitions.
With Powter:
Notice the only testing dependency is the user.js file. Also notice the lightweight stubs for the req and res objects
Without Powter:
Notice the extra dependancies, the authorization, and the fact that we have to import an entire HTTP Server!
Getting Started
A powter configuration file can be as simple or as verbose as needed.
By default, all functions can be named after the intended HTTP method, but names can be specified as needed.
Here is a basic example:
server.js
Pass the express app and config file path into powter so it can build the routes
const express = const powter = const app = // Build the routes
routes.json
Configure you're API
user.js
{ // Handle Request} { // Handle Request} { // Handle Request} { // Handle Request} { // Handle Request}
order.js
{ // Handle Request} { // Handle Request} { // Handle Request}