All Projects → Jinxiansen → Guardian

Jinxiansen / Guardian

Licence: MIT License
Service Side Swift:Vapor 3 based API Guardian Middleware. 🦁

Programming Languages

swift
15916 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Guardian

horse-logger
Middleware for access logging in HORSE
Stars: ✭ 25 (-72.22%)
Mutual labels:  middleware
MeowVapor
Meow plugin for API generation
Stars: ✭ 12 (-86.67%)
Mutual labels:  vapor
puffery
A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.
Stars: ✭ 17 (-81.11%)
Mutual labels:  vapor
whoops-middleware
PSR-15 compatible middleware for Whoops, the pretty error handler
Stars: ✭ 24 (-73.33%)
Mutual labels:  middleware
express-firebase-middleware
🔥 Express middleware for your Firebase applications
Stars: ✭ 53 (-41.11%)
Mutual labels:  middleware
interface-doc
The technical specification of the data interface that describes how to integrate the fiskaltrust Middleware into POS systems.
Stars: ✭ 17 (-81.11%)
Mutual labels:  middleware
spiderable-middleware
🤖 Prerendering for JavaScript powered websites. Great solution for PWAs (Progressive Web Apps), SPAs (Single Page Applications), and other websites based on top of front-end JavaScript frameworks
Stars: ✭ 29 (-67.78%)
Mutual labels:  middleware
fuxedo
An Open Source alternative to Oracle Tuxedo
Stars: ✭ 15 (-83.33%)
Mutual labels:  middleware
email
A common API for Vapor to integrate with different email providers
Stars: ✭ 13 (-85.56%)
Mutual labels:  vapor
rmw ecal
ROS2 middleware based on eCAL
Stars: ✭ 30 (-66.67%)
Mutual labels:  middleware
express-ping
Let all your express applications expose a common API to inform about their internal status and health.
Stars: ✭ 50 (-44.44%)
Mutual labels:  middleware
postgres-kit
🐘 Non-blocking, event-driven Swift client for PostgreSQL.
Stars: ✭ 125 (+38.89%)
Mutual labels:  vapor
mooseware
💀 Skeleton for writing a middleware handler
Stars: ✭ 47 (-47.78%)
Mutual labels:  middleware
AspNetCore.Weixin
An ASP.NET Core middleware for Wechat/Weixin message handling and apis. (微信公众平台/接口调用服务)
Stars: ✭ 24 (-73.33%)
Mutual labels:  middleware
server-timing
Collect backend metrics and provide them as Server-Timing header in your responses
Stars: ✭ 34 (-62.22%)
Mutual labels:  middleware
catbird
Mock server for UI tests
Stars: ✭ 32 (-64.44%)
Mutual labels:  vapor
jwt-auth
JSON Web Token Authentication for Laravel and Lumen
Stars: ✭ 46 (-48.89%)
Mutual labels:  middleware
express-view-cache
Unobtrusive solution to express framework - cache rendered page, without database requests and rendering.
Stars: ✭ 20 (-77.78%)
Mutual labels:  middleware
doa
A middleware framework for Deno's http serve🦕. Transplanted from Koa with ❤️
Stars: ✭ 20 (-77.78%)
Mutual labels:  middleware
rbac
RBAC - Simple, concurrent Role Based Access Control(GO)
Stars: ✭ 67 (-25.56%)
Mutual labels:  middleware



Guardian Version Swift Version Vapor Version GitHub license

[中文版🇨🇳]

Guardian is a Vapor 3 based Middleware that limits the number of requests from the client based on the IP address + access URL. It works by adding the client's IP address to the cache and counting the number of requests that the client can make within the lifecycle defined when the GuardianMiddleware is added, and returns HTTP 429 (too many requests) when the limit is reached. After the time limit expires, the request can be re-initiated,And support custom return data. The reason Guardian generates is because gatekeeper only supports vapor 2 , thanks very much to the original author! 🍺

Consider that if there is a public IP address in the LAN, increase the unit threshold appropriately.

Installation 📦

To include it in your package, add the following to your Package.swift file.

let package = Package(
    name: "Project",
    dependencies: [
        ...
        .package(url: "https://github.com/Jinxiansen/Guardian.git", from: "3.0.0"),
    ],
    targets: [
      .target(name: "App", dependencies: ["Guardian", ... ])
    ]
)
        

Usage 🚀

There are two ways to use:

  • Global use:

Guardian Configurable fields: Maximum number of visits, time units, and cache to use.

If you do not provide your own cache, Guardian will create its own memory cache.

// Each api URL is limited to 20 times per minute
let guardian = GuardianMiddleware(rate: Rate(limit: 20, interval: .minute)) 

or

on configure.swift

  1. Import header files
import Guardian
  1. Join before services
var middlewares = MiddlewareConfig() 

middlewares.use(GuardianMiddleware(rate: Rate(limit: 25, interval: .minute), closure: { (req) -> EventLoopFuture<Response>? in
	let view = ["result":"429","message":"The request is too fast. Please try again later!"]
	return try view.encode(for: req)
}))

services.register(middlewares)

Method Two:

  • Routing group use:

Adding Middleware to a Routing Group

 
let group = router.grouped(GuardianMiddleware(rate: Rate(limit: 25, interval: .minute)))

group.get("welcome") { req in
    return "hello,world !"
}

Support custom return data 📌

Guardian adds support for custom return data, as in the following example:

Return a JSON object:

middlewares.use(GuardianMiddleware(rate: Rate(limit: 20, interval: .minute), closure: { (req) -> EventLoopFuture<Response>? in
	let view = ["result":"429","message":"The request is too fast. Please try again later!"]
	return try view.encode(for: req)
}))

or return a Leaf/Html web page:

middlewares.use(GuardianMiddleware(rate: Rate(limit: 25, interval: .minute), closure: { (req) -> EventLoopFuture<Response>? in
	let view = try req.view().render("leaf/busy")
	return try view.encode(for: req)
}))

or Custom returns other types of data...

Rate.Interval Enumeration types

Currently supported setup intervals are:

case .second
case .minute
case .hour
case .day

Contacts

If you have any questions or suggestions you can raise one Issues or contact me:

Email : [email protected]

Twitter : @Jinxiansen

License 📄

Guardian is released under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].