Skip to content

Blazheiko/uwebsockets-api

Repository files navigation

🇺🇦 Stand With Ukraine - Support Independence, Resist Russian Aggression 🇺🇦

🇮🇱 Stand With Israel - Support its Fight Against Terrorism 🇮🇱

uWebSockets API

uWebSockets-api — This wrapper simplifies the usage of uWebSockets.js by offering more convenient tools for handling WebSockets and HTTP routing.

Basics

This wrapper simplifies the usage of uWebSockets.js by offering more convenient tools for handling WebSockets and HTTP routing.

Installation

You can install uWebSockets-api clone project https://github.com/Blazheiko/uwebsockets-api.git

Install dependencies npm install

Create .env file following the .env.example

Start server node start.js || npm run prod

Starting the server in development mode node dev.js || npm run dev

Usage Example

Inspired by the frameworks Laravel and AdonisJs, uWebSockets-api aims to provide a similar experience in organizing project structure and route descriptions.

routing http app/routes/httpRoutes.js

import MainController from '#app/controllers/http/MainController.js';

export default [
  {
    url: '/test-middleware',
    method: 'get',
    handler: MainController.testMiddleware,
    middlewares: ['test1'],
  },
  {
    group: [
      {
        url: '/init',
        method: 'get',
        handler: MainController.init,
      },
      {
        url: '/save-user',
        method: 'post',
        handler: MainController.saveUser,
        validator: 'register',
      },
    ],
    middlewares: ['test2'],
    prefix: '/api',
  },
];

routing ws app/routes/wsRoutes.js

import WSApiController from '#app/controllers/ws/WSApiController.js';

export default [
  {
    group: [
      {
        url: 'test',
        handler: WSApiController.test,
      },
      {
        url: 'error',
        handler: WSApiController.error,
        middleware: 'test2',
      },
      {
        url: 'save-user',
        handler: WSApiController.saveUser,
        validator: 'register',
      },
    ],
    prefix: 'api:',
  },
];

Modules used

Query Builder database/db.js khex

Redis client database/redis.js ioredis

Validator app/validate/schemas/schemas.js VineJS

Logger logger.js pino

Library for working with dates and times Luxon

Utils Metarhia utilities

License

uWebSockets-api is released under the MIT License.

Support and Contribution

If you have questions or suggestions, please create an issue in our GitHub repository. We also welcome your pull requests with improvements and corrections.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published