diff --git a/.gitignore b/.gitignore index f375b7e..3510170 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .* !.git* +!docs/.assets bun.lock* package-lock.json node_modules diff --git a/README.md b/README.md index 8ced6bd..691029e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/Getting Started.md b/docs/Getting Started.md deleted file mode 100644 index acf03fb..0000000 --- a/docs/Getting Started.md +++ /dev/null @@ -1,3 +0,0 @@ -# Getting Started - -Test custom document file \ No newline at end of file diff --git a/docs/Guides/Dynamic Routes.md b/docs/Guides/Dynamic Routes.md new file mode 100644 index 0000000..7bcf179 --- /dev/null +++ b/docs/Guides/Dynamic Routes.md @@ -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. \ No newline at end of file diff --git a/docs/Guides/Getting Started.md b/docs/Guides/Getting Started.md new file mode 100644 index 0000000..0cdf5c1 --- /dev/null +++ b/docs/Guides/Getting Started.md @@ -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) diff --git a/docs/assets/DynamicRoutes-example1.png b/docs/assets/DynamicRoutes-example1.png new file mode 100644 index 0000000..61f7f7d Binary files /dev/null and b/docs/assets/DynamicRoutes-example1.png differ diff --git a/docs/assets/HelloWorld.png b/docs/assets/HelloWorld.png new file mode 100644 index 0000000..32df55c Binary files /dev/null and b/docs/assets/HelloWorld.png differ