Catalog npm
PACKAGE EXPLORERView in registry

0xapi

npm

is a lightweight library for quickly setting up APIs with Express.

apiauthenticationexpresslightweightrate-limiterwrapper
Versions collected4
Direct dependencies2From release 1.1.0
Last observed20 Oct, 17:49 UTC

README

Current package documentation

0xapi

0xapi is a lightweight library for quickly setting up APIs with Express. It simplifies the API creation process and ensures compatibility with popular Express extensions, like express-rate-limit. With minimal configuration, you can easily structure your API, manage routes, and extend your app's functionality.

Features

  • Simple API and router creation
  • Compatible with popular Express extensions (e.g., express-rate-limit)
  • Easy setup for versioned APIs
  • Flexible routing with minimal configuration
  • Built-in support for rate limiting, authentication, and more

Installation

To install 0xapi, run the following command:

npm install 0xapi

Usage

Basic Setup

0xapi allows you to create APIs with versioned routes. Below is an example of setting up a versioned API with rate limiting and authentication.

const { API, Router, Auth, RateLimiter } = require("0xapi");

const Authization = new Auth([                      // Creates an auth gateway for your API.
    "cd9e7837-9194-4009-ad2c-b698368b8423"
]);

const apiV1Router = new Router({ name: "V1 API", path: "/api/v1" });           // Creates a route for /api/v1
const apiV2Router = new Router({ name: "V2 API", path: "/api/v2" });           // Creates a route for /api/v2

apiV1Router.get("/", (req, res) => { res.json({ timestamp: Date.now() }); });  // Creates a GET endpoint at /api/v1/
apiV2Router.get("/", (req, res) => { res.json({ timestamp: Date.now() }); });  // Creates a GET endpoint at /api/v2/

// Rate limiter setup
const limiter = new RateLimiter({
    window: 5 * 60 * 1000,  // Limit requests to every 5 minutes
    max: 100,               // Max 100 requests per window
    message: "Too many requests from this IP, please try again later."
});

const api = new API({                   // Creates an API instance.
    port: 8081,                         // Set the API to run on port 8081.
    Routers: [apiV1Router, apiV2Router]  // Attach versioned routers to the API.
});

// Apply the rate limiter globally
api.use(limiter);

// Apply the authorization gateway globally
api.use(Authization);

api.listen(() => {                      // Start the API.
    console.log("API is running");      // Log a message when the API starts.
});

Explanation

  • Router Setup: You define versioned routes (e.g., /api/v1, /api/v2) using Router. This helps organize your API endpoints into logical versions.

  • Rate Limiting: The RateLimiter class is used to limit the number of requests per IP in a 5-minute window (maximum of 100 requests). If the limit is exceeded, the message "Too many requests from this IP, please try again later" is sent.

  • Authentication: The Auth class provides an easy way to enforce authentication in your API. In the example, an API key "cd9e7837-9194-4009-ad2c-b698368b8423" is required for accessing the routes. If a request doesn't include a valid API key, it is denied.

  • API Initialization: Create an API instance, attach routers, and start the server on port 8081. The rate limiter and authentication middleware are applied globally using api.use().

Compatibility

0xapi is fully compatible with popular Express extensions. In the above example, RateLimiter is used to manage the rate of requests, and Auth is used to secure the API. You can easily integrate other middlewares or extensions to suit your app’s needs.

Documentation

For more detailed documentation, visit the GitHub repository:

https://github.com/ShadyM00n/0xapi

Contributing

Feel free to submit issues or pull requests. Contributions are welcome!

License

MIT License. See the License file for more details.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 4

Collected releases
VersionPublishedDirect dependenciesOpen version
1.1.0Registry latest11 May 20252
1.0.0-stable11 May 20251
1.0.011 May 20251
0.0.111 May 20251

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
shadym00n/0xapi

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 17:49 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:fd34d57380491ed7cf84f2c158cb025ea7a5be7b679477fd418bd19ddd94d592