-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from IsCoffeeTho/26-Documentation
Merge with main for production
- Loading branch information
Showing
7 changed files
with
109 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.* | ||
!.git* | ||
!docs/.assets | ||
bun.lock* | ||
package-lock.json | ||
node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
``` | ||
|
||
 | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.