Skip to content

Commit

Permalink
Merge pull request #27 from IsCoffeeTho/26-Documentation
Browse files Browse the repository at this point in the history
Merge with main for production
  • Loading branch information
IsCoffeeTho authored Feb 17, 2025
2 parents e67bf82 + aa14ecf commit 2882a92
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.*
!.git*
!docs/.assets
bun.lock*
package-lock.json
node_modules
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,23 @@ ToastieBun is an express like bun based http server framework.
```bash
bun install toastiebun
```
## Testing
### Usage
```ts
// index.ts

import toastiebun from "toastiebun";

const app = new toastiebun.server();

app.get("/", (req, res) => {
res.send("Hello from Toastiebun");
})

app.listen("127.0.0.1", 8000);
```
![Hello from Tostiebun](./docs/.assets/HelloWorld.png)

## Development
```bash
# Unit Tests
bun test
Expand Down
3 changes: 0 additions & 3 deletions docs/Getting Started.md

This file was deleted.

34 changes: 34 additions & 0 deletions docs/Guides/Dynamic Routes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Dynamic Routes

## Introduction

Often when making a website there will be a need to have content available after the fact of writing the code. You could just continuously add `.get` handlers to accommodate but this doesn't handle the case where things get deleted.

Let's write an example about handling requests where you could have a variable name in the path and how to access the variable.
## Example

Suppose you want to write a blog and want to separate out the various

```ts
import toastiebun from "toastiebun";

const app = new toastiebun.server();

app.get("/post/:community/:slug", (req, res) => {
res.send({
status: "success",
post: {
community: req.params.community,
slug: req.params.slug,
}
})
});

app.listen("::", 8000, () => {
console.log("Server running at http://localhost:8000");
});
```

![Example 1](../assets/DynamicRoutes-example1.png)

This is great for simple pages that are stored somewhere else and can be accessed by the server however, dynamic routes can also be used to write APIs with a bit more complex structuring.
57 changes: 57 additions & 0 deletions docs/Guides/Getting Started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Getting Started

## Introduction

Welcome to **ToastieBun**, a lightweight and high-performance express-like HTTP(S) server framework tailored for the [Bun](https://bun.sh/) runtime. Built for speed and simplicity, ToastieBun provides an intuitive API to help developers quickly set up and manage web servers. This guide will walk you through the installation, setup, and fundamental features to get you started.

Note is that ToastieBun is **NOT** a drop in replacement for express.
## Prerequisites

Before you start, ensure you have the following:

- **Bun installed**: If you haven't installed Bun yet, follow the instructions at [Bun's official website](https://bun.sh/).
- **A working terminal** (Linux/macOS/Windows with WSL or Git Bash recommended).

To check if Bun is installed, run:

```bash
bun --version
```

## Creating your first ToastieBun Server

1. Create a new project folder and navigate into it:
```bash
mkdir my-website && cd my-website
```
2. Initialize a Bun project:
```bash
bun init
```
3. Install ToastieBun:
```bash
bun install toastiebun
```
4. Create an `index.ts` file and add the following code:

```typescript
import toastiebun from "toastiebun"; // v0.4.11

const app = new toastiebun.server();

app.get("/", (req, res) => {
res.send("Hello from ToastieBun");
});

app.listen("::", 8000, () => {
console.log("Server running at http://localhost:8000");
});
```

5. Start the server:
```bash
bun run index.ts
```

6. Open your browser and visit `http://localhost:8000`. You should see `Hello, ToastieBun!` displayed.
![Hello from Toasteibun](../assets/HelloWorld.png)
Binary file added docs/assets/DynamicRoutes-example1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/HelloWorld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2882a92

Please sign in to comment.