📝 Update Readme

This commit is contained in:
Christian van Dijk
2026-02-19 17:18:40 +01:00
parent 64ee67d10c
commit 13058e09f5

View File

@@ -1,3 +1,70 @@
# GiteaTest
# 🚀 Tiny Lua HTTP Server
My First Gitea Repo
A lightweight, zero-framework HTTP server built using **Lua** and **LuaSocket**. This project demonstrates how to handle basic routing, query parameter parsing, and manual HTTP response construction with a minimal footprint.
![Lua Version](https://img.shields.io/badge/lua-5.1%2B-blue.svg)
![License](https://img.shields.io/badge/license-MIT-green.svg)
## ✨ Features
* **Zero Dependencies:** Only requires `luasocket`.
* **Minimal Footprint:** The entire server logic is under 50 lines of code.
* **Query Parsing:** Dynamically greets users via URL parameters.
* **Basic Routing:** Returns a `404 Not Found` for any path other than `/hello`.
---
## 🛠️ Getting Started
### 1. Prerequisites (macOS)
Ensure you have **Homebrew** installed, then set up Lua and LuaRocks:
```bash
# Install Lua and the Package Manager
brew install lua luarocks
# Add LuaRocks to your shell path
eval $(luarocks path --bin)
```
### 2. Install Dependencies
Install the networking library used by the server:
`luarocks install luasocket`
### 3. Run the Server
Clone this repository (or save the script as server.lua) and execute:
`lua server.lua`
The server will start at http://localhost:8080.
---
## 📡 API Reference
The server currently supports a single endpoint:
`/hello`
`HTTP GET`
`?name=YourName` (optional)
Returns a greeting. Defaults to "User".
Examples
Greet a specific user:
`curl "http://localhost:8080/hello?name=Raycast"`
`Output: Hello Raycast!`
Default greeting:
`curl "http://localhost:8080/hello"`
`Output: Hello User!`
---
## 📂 Project Structure
- server.lua
Main server logic including socket handling and routing.
- README.md
Documentation and setup instructions.
---
## 🧠 How it Works
1. Socket Binding: The server binds to localhost:8080 and waits for incoming TCP connections. 2. Request Parsing: It reads the first line of the HTTP request and uses Lua's powerful Pattern Matching to extract the URI. 3. Routing: It checks if the path matches /hello. 4. Response: It manually constructs a valid HTTP/1.1 response string, including headers like Content-Type and Content-Length.
## 📄 License
This project is open-source and available under the MIT License.