0.4.4 • Published 5 months ago

@ionited/fiber v0.4.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Fiber

A fast web framework based on uWebSocket.js

About uWebSockets.js

µWebSockets.js is a web server bypass for Node.js that reimplements eventing, networking, encryption, web protocols, routing and pub/sub in highly optimized C++. As such, µWebSockets.js delivers web serving for Node.js, 8.5x that of Fastify and at least 10x that of Socket.IO. It is also the built-in web server of Bun.

Quick start

Install with NPM

npm i @ionited/fiber

Documentation

App

const app = new App();

app

.use((req, res) => console.log('Hello World!'))

.catch((e, req, res) => res.status(e.status ?? 500).json({ message: e.message ?? 'Internal server error' }))

.notFound((req, res) => res.status(404).end())

.any('/users', (req, res) => res.json({ success: true }))

.del('/users', (req, res) => res.json({ success: true }))

.get('/users', (req, res) => res.json({ success: true }))

.options('/users', (req, res) => res.json({ success: true }))

.post('/users', (req, res) => res.json({ success: true }))

.put('/users', (req, res) => res.json({ success: true }))

.ws('/ws', {
  close: (ws, code, message) => {},
  message: (ws, message) => {},
  open: ws => {}
})

.listen(1000);

Router

const router = new Router('/public')

router

.use((req, res) => console.log('Hello World!'))

.any('/users', (req, res) => res.json({ success: true }))

.del('/users', (req, res) => res.json({ success: true }))

.get('/users', (req, res) => res.json({ success: true }))

.options('/users', (req, res) => res.json({ success: true }))

.post('/users', (req, res) => res.json({ success: true }))

.put('/users', (req, res) => res.json({ success: true }))

.ws('/ws', {
  close: (ws, code, message) => {},
  message: (ws, message) => {},
  open: ws => {}
});

const routes = router.routes();

HttpRequest

interface HttpRequest {
  body(): Promise<{ [key: string]: any }>;
  data: { [key: string]: any };
  files(): Promise<{ [key: string]: UploadedFile | undefined }>;
  headers(): { [key: string]: string };
  params(): { [key: string]: string };
  query(): { [key: string]: any };
  url(): string;
}

HttpResponse

interface HttpResponse {
  end(text?: string): void;
  header(key: string, value: string): this;
  json(json: any): void;
  send(text: string): void;
  sendFile(path: string): Promise<void>;
  status(status: number): this;
}

UploadedFile

interface UploadedFile {
  data: ArrayBuffer;
  filename: string;
  type: string;
}

WebSocket

interface WebSocket {
  send(message: string): void;
}

WebSocketBehavior

export interface WebSocketBehavior {
  close?: (ws: WebSocket, code: number, message: ArrayBuffer) => void;
  message?: (ws: WebSocket, message: ArrayBuffer) => void;
  open?: (ws: WebSocket) => void;
}

License

Copyright (c) 2023 Ion. Licensed under MIT License.

https://ionited.io

0.4.4

5 months ago

0.3.0

7 months ago

0.2.1

8 months ago

0.2.0

10 months ago

0.4.1

6 months ago

0.2.3

7 months ago

0.4.0

7 months ago

0.2.2

7 months ago

0.4.3

5 months ago

0.4.2

6 months ago

0.1.11

11 months ago

0.1.10

11 months ago

0.1.9

11 months ago

0.1.8

11 months ago

0.1.7

11 months ago

0.1.6

11 months ago

0.1.5

11 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago