https://github.com/johndavedecano/lizard
https://github.com/johndavedecano/lizard
api bun javascript oop typescript
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/johndavedecano/lizard
- Owner: johndavedecano
- Created: 2025-01-21T02:25:26.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-01-26T06:45:14.000Z (6 months ago)
- Last Synced: 2025-03-27T19:15:15.732Z (4 months ago)
- Topics: api, bun, javascript, oop, typescript
- Language: TypeScript
- Homepage:
- Size: 53.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lizard
Lizard is a lightweight wrapper on top of [Bun](https://bun.sh), a fast all-in-one JavaScript runtime. This project provides a simple and efficient way to create web applications with minimal setup.
## Features
- **Fast and Lightweight**: Built on Bun, ensuring high performance.
- **Simple Routing**: Define routes easily with support for dynamic parameters.
- **Middleware Support**: Add middleware functions to handle requests.
- **TypeScript Support**: Written in TypeScript for type safety and better development experience.## Installation
To install dependencies, run:
```bash
bun install
```## Running the Application
To start the application, run:
```bash
bun run index.ts
```The server will start on port 3000 by default.
## Project Structure
```plaintext
├── .gitignore
├── bun.lockb
├── index.ts
├── lizard.ts
├── package.json
├── README.md
├── tsconfig.json
├── types.ts
├── utils.test.ts
└── utils.ts
```- **index.ts**: Entry point of the application.
- **lizard.ts**: Core framework implementation.
- **types.ts**: Type definitions for the framework.
- **utils.ts**: Utility functions used by the framework.
- **utils.test.ts**: Unit tests for utility functions.## Example Usage
Here is an example of how to define routes in your application:
```ts
import Lizard from "./lizard";
import type { Middleware } from "./types";const app = Lizard.create();
// Global middleware to log requests
const loggerMiddleware: Middleware = async (event, next) => {
console.log(`Request: ${event.method} ${event.url}`);
return next();
};// Global middleware to add a custom header
const headerMiddleware: Middleware = async (event, next) => {
event.response.headers.set('X-Custom-Header', 'Lizard');
return next();
};// Apply global middlewares
app.use(loggerMiddleware);
app.use(headerMiddleware);app.get('/', async (event) => {
return event.response.send("Hello, World!");
});app.get('/home', async (event) => {
return event.response.send("Home Page");
});app.get('/home/:id', async (event) => {
return event.response.send("Home Page" + event.params?.id);
});app.get('/home/:id', async (event) => {
return event.response.send(`User ${event.params?.id}`);
});app.get('/home/:id', async (event) => {
return event.response.send(`User ${event.params?.id}`);
});app.get('/home/:id/profile', async (event) => {
return event.response.send(`User ${event.params?.id} Profile`);
});app.post('/user', async (event) => {
return event.response.send("User Created");
});app.put('/user/:id', async (event) => {
return event.response.send(`User ${event.params?.id} Updated`);
});app.del('/user/:id', async (event) => {
return event.response.send(`User ${event.params?.id} Deleted`);
});app.listen(3000);
```In this example, the middleware sets a `user` object in the `event.locals` property. The `/profile` route then accesses this local variable and returns the user's name in the response.
## License
This project is licensed under the MIT License.