packet based asynchronous rest library for backend applications.
(read -> handle -> write)
๐ Documents ๐ ยท ๐ท๏ธ Report Bug ๐ท๏ธ ยท ๐ Request Feature ๐
Contents
Packetify is an understandable asynchronous library made to make your backend works easier (RESTAPI, jwt-token based authentication etc.)
Here's why:
- It is an easy to use library, no need to waste time anymore!
- It is an understandable library.
- It is an asynchronous library.
In this project, `fastify` was used as server base, `zod` was used as validation, `@fastify/jwt` was used as authentication token library.
- Install with
npm
oryarn
npm install packetify
with yarn
yarn add packetify
- Read the documents
- wake(), eat(), code(), sleep(), repeat() !
const packetify: Packetify = new Packetify()
// registering packets etc.
packetify.listen(PORT) // Default Port: 45317
import { Packet } from 'packetify'
@PacketifyPacket("/my/path/:id",
PacketMethod.GET, // PacketMethod.GET or PacketMethod.POST (under construction)
z.object({ // Query Schema (zod)
username: z.string().min(5).max(16),
password: z.string()
}))
class MyPacket extends Packet {
/**
*
* READING QUERY & PARAMS DATA
*
*/
read(data: any): void {
this.data = data;
}
/**
*
* HANDLING SOMETHINGS
*
*/
handle(): void {
console.log(this.data.query)
}
/**
*
* RESPONSE (SUCCESSFUL)
*
*/
write() {
return {"asdasdasd": "asdasd"};
}
/**
*
* ERROR HANDLING (zod query errors etc.)
*
*/
onError(error: FastifyError, request: FastifyRequest): void {
console.log(error)
reply.send("ERROR!")
}
}
For more examples, please refer to the Documentation
Distributed under the MIT License. See LICENSE
for more information.