Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vyder/bunbox
A framework to build APIs with bun
https://github.com/vyder/bunbox
Last synced: about 1 month ago
JSON representation
A framework to build APIs with bun
- Host: GitHub
- URL: https://github.com/vyder/bunbox
- Owner: vyder
- Created: 2024-01-23T15:11:11.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-01-23T19:57:04.000Z (8 months ago)
- Last Synced: 2024-07-12T11:31:50.636Z (2 months ago)
- Language: TypeScript
- Size: 7.81 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bun Box
## Installation
1. Install [bun](https://bun.sh) & create a new project
```sh
❯ mkdir bunbox-example && cd bunbox-example
❯ bun init
# work through prompts
❯ bun install
```2. Install `bunbox`
```sh
❯ bun add bunbox
```## Usage
My goal with this project is to hideaway as much of the boiler plate import
crud as I can, following in the footsteps of frameworks like Rails.By default, this is the directory structure `bunbox` expects:
```
|
|- index.ts
|- controllers/
|- hello.ts
```1. Create a controller:
```ts
// controllers/hello.ts
import { Controller } from "bunbox"
import type { Context } from "bunbox"class HelloController implements Controller {
route: string
method: stringconstructor() {
this.method = "GET"
this.route = "/hello"
}run = (c: Context) => c.text("Hello!")
}export default HelloController
```or in vanilla JavaScript:
```js
// controllers/hello.js
class HelloController {
constructor() {
this.method = "GET"
this.route = "/hello"
}run = c => c.text("Hello")
}
```4. Update your `index.ts`:
```ts
import BunBox from "bunbox"
const box = new BunBox()box.serve()
```5. Run with `bun run index.ts`:
```sh
❯ curl localhost:3000/hello
Hello!
```