# bunnet

> Developer-friendly library for building and managing powerful APIs with ease and efficiency

Latest version **0.0.6** (published 2023-12-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install bunnet
pnpm add bunnet
yarn add bunnet
bun add bunnet
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2023-12-02 |
| First published | 2023-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Nir Arad |
| Maintainers | nir10 |
| Keywords | bunNET, bun, framework, rest, restful, http, web, router, app, api |

## Links

- npm: https://www.npmjs.com/package/bunnet
- Repository: https://github.com/NirArad10/bunNET
- Homepage: https://github.com/NirArad10/bunNET#readme
- Issues: https://github.com/NirArad10/bunNET/issues
- npm.io page: https://npm.io/package/bunnet

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 0.0.6 (latest) — 2023-12-02
- 0.0.5 — 2023-10-05
- 0.0.4 — 2023-09-30
- 0.0.3 — 2023-09-28
- 0.0.2 — 2023-09-25
- 0.0.1 — 2023-09-20

## README

# bunNET
![npm](https://img.shields.io/npm/v/bunnet)
![npm](https://img.shields.io/npm/dt/bunnet)
![npm](https://img.shields.io/npm/l/bunnet)
[![CodeFactor](https://www.codefactor.io/repository/github/NirArad10/bunNET/badge)](https://www.codefactor.io/repository/github/NirArad10/bunNET)\
Developer-friendly library for building and managing powerful APIs with ease and efficiency

## Installation

You can install `bunNET` via bun by running the following command:

```bash
bun install bunnet
```

## Usage

To use `bunNET` in your project, follow these steps:

1. Import the `bunnet` singleton into your project and create a class to set up your HTTP server:

```js
import bunnet from 'bunnet';

const app = bunnet();
```

2. Define routes and associated handler functions for different HTTP methods:

```js
app.get('/api/resource', (req, res) => {
	// Your GET request handler logic here
});

app.post('/api/resource', (req, res) => {
	// Your POST request handler logic here
});

// Add more routes as needed...
```

### Dynamic Routes

You can define dynamic routes using `:` in your route paths. For example:

```js
app.get('/api/user/:id', (req, res) => {
	const userId = req.params.id;
	// Your logic to handle requests with a dynamic user ID
});
```

3. **Request Functions**

   The `BunNETRequest` class provides several utility functions for working with the request body:

   - `text()`: Reads the request body as text.
   - `json()`: Parses the request body as JSON.
   - `formData()`: Parses the request body as form data.
   - `blob()`: Reads the request body as a binary blob.
   - `array()`: Reads the request body as an array of bytes.
   - `arrayBuffer()`: Reads the request body as an ArrayBuffer.

   Here's an example of how to use the `text()` and `json()` functions:

   ```js
   app.post('/api/submit', async (req, res) => {
   	try {
   		const requestBodyText = await req.text();
   		const requestBodyJSON = await req.json();

   		// Process the request body data
   		// ...

   		res.send('Request received and processed.');
   	} catch (error) {
   		console.error('Error processing request:', error);
   		res.status(500).send('Internal server error');
   	}
   });
   ```

4. Start the server by specifying a port number:

```js
const PORT = 3000;

app.listen(PORT, () => {
	console.log(`Server is running on port ${PORT}`);
});
```

5. Run your application:

```bash
bun your-app.js/ts
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---
_Source: https://npm.io/package/bunnet · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
