Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Passport | 21,300 | 81,272 | 3,916 | an hour ago | 32 | May 20, 2022 | 363 | mit | JavaScript | |
Simple, unobtrusive authentication for Node.js. | ||||||||||
Grant | 3,771 | 210 | 41 | 3 months ago | 98 | March 09, 2022 | 23 | mit | JavaScript | |
OAuth Proxy | ||||||||||
Everyauth | 3,480 | 745 | 38 | 5 years ago | 61 | October 17, 2014 | 175 | JavaScript | ||
node.js auth package (password, facebook, & more) for Connect and Express apps | ||||||||||
Node Express Realworld Example App | 3,434 | 1 | a month ago | 1 | June 28, 2018 | 73 | JavaScript | |||
Express Mongoose Es6 Rest Api | 2,896 | 3 years ago | 1 | September 03, 2016 | 68 | mit | JavaScript | |||
:collision: A boilerplate application for building RESTful APIs Microservice in Node.js using express and mongoose in ES6 with code coverage and JsonWebToken Authentication | ||||||||||
Node Rate Limiter Flexible | 2,389 | 68 | 81 | 2 months ago | 146 | September 25, 2022 | 9 | isc | JavaScript | |
Count and limit requests by key with atomic increments in single process or distributed environment. | ||||||||||
Iron Session | 2,384 | 8 | a day ago | 51 | September 09, 2022 | 59 | mit | TypeScript | ||
🛠 Next.js stateless session utility using signed and encrypted cookies to store data. Also works with Express, and Node.js HTTP servers | ||||||||||
Foal | 1,722 | 7 | 22 | 2 months ago | 77 | May 29, 2022 | 22 | mit | TypeScript | |
Full-featured Node.js framework, with no complexity. 🚀 Simple and easy to use, TypeScript-based and well-documented. | ||||||||||
Permit | 1,664 | 8 | 4 | 5 months ago | 8 | July 17, 2018 | 8 | mit | JavaScript | |
An unopinionated authentication library for building Node.js APIs. | ||||||||||
Accountill | 1,354 | a day ago | 16 | mit | JavaScript | |||||
Fullstack open source Invoicing application made with MongoDB, Express, React & Nodejs (MERN) |
This is an express.js-like-middleware-chain for julienschmidt's httprouter
You can write your own middleware, and chain this to a lot of other middlewares (logging, auth,...).
go get github.com/TobiEiss/goMiddlewareChain
Here a simple example with a simple Ping-Pong-Handler chained with a JSONResponseHandler (from templates).
package main
import (
"fmt"
"log"
"net/http"
"github.com/julienschmidt/httprouter"
"github.com/TobiEiss/goMiddlewareChain"
"github.com/TobiEiss/goMiddlewareChain/templates"
)
// Ping return a simply pong
func Ping(response *goMiddlewareChain.Response, request *http.Request, params httprouter.Params) {
// simply pong
response.Status.Code = http.StatusOK
response.Data = "pong"
}
func main() {
router := httprouter.New()
router.GET("/api/v0/ping", goMiddlewareChain.RequestChainHandler(templates.JSONResponseHandler, Ping))
log.Fatal(http.ListenAndServe(":8080", router))
}
After running this code, run curl localhost:8080/api/v0/ping
in a terminal.
You will get the following:
{
"data":"pong",
"msg":"OK",
"status":200
}
Isn't it cool?
In some cases you need a restriction to apply requestChain. For example an auth-restriction.
You can use the RestrictedRequestChainHandler
. If the RestrictHandler
failed, the code doesn't pass the chain.
Same example with Auth:
package main
import (
"log"
"net/http"
"github.com/TobiEiss/goMiddlewareChain"
"github.com/TobiEiss/goMiddlewareChain/templates"
"github.com/julienschmidt/httprouter"
)
// Ping return a simply pong
func Ping(response *goMiddlewareChain.Response, request *http.Request, params httprouter.Params) {
// simply pong
response.Status.Code = http.StatusOK
response.Data = "pong"
}
func Auth(response *goMiddlewareChain.Response, request *http.Request, params httprouter.Params) bool {
user := request.Header.Get("X-User")
return user == "HomerSimpson"
}
func main() {
router := httprouter.New()
router.GET("/api/v0/ping", goMiddlewareChain.RestrictedRequestChainHandler(Auth, templates.JSONResponseHandler, Ping))
log.Fatal(http.ListenAndServe(":8080", router))
}
Now run curl --header "X-User: HomerSimpson" localhost:8080/api/v0/ping
in your terminal. You will get:
{
"data":"pong",
"msg":"OK",
"status":200
}
If you run curl --header "X-User: BartSimpson" localhost:8080/api/v0/ping
, you get:
{
"msg":"failed by passing restrictHandler",
"status":401
}
You need more handler? Just let us now this.