A simple HTTP server written in Go.
Perfect for beginners who want to learn the basics of web servers and Go programming!
Let’s make your browser say “Hello” like never before! 👋
- Serves HTTP requests
- Easy to understand
- Minimal dependencies
- Go 1.18+ installed on your system
- Internet connection (for cloning the repository)
- (Optional) Postman or
curlfor testing POST requests
Don’t worry, even your grandma could run this server. Just follow these steps!
-
Clone this repository:
git clone https://github.com/hrosicka/SimpleServer.git
cd SimpleServer -
Run the server:
go run main.go handlers.go types.go
-
Access the server: Open your browser and visit http://localhost:8080
Make sure you have Go installed. Then, run the server from the project directory.
Server provides two GET endpoints that can be tested directly from the browser by entering the URL. Both endpoints accept query parameters, so you can easily customize the request.
Returns a personalized JSON greeting message. Optionally takes a name parameter via the query string.
Try changing the name for a different greeting. The server never gets tired of saying hello!
-
Open your browser.
-
In the address bar, enter (replace
Hankawith any name you like):http://localhost:8080/hello?name=Hanka -
Response: You’ll see a JSON message like:
{ "message": "Hello Hanka!" }
Returns a JSON message and echoes back the provided id and type parameters.
Send your data and see it come right back at you! It’s like playing catch with a server.
-
Open your browser.
-
In the address bar, enter (replace
123456anduserwith any name you like):http://localhost:8080/data?id=123456&type=user -
Response: You’ll see a JSON message like:
{ "message": "Data retrieved.", "data": { "id": "123456", "type": "user" } }
Accepts a JSON object with name, surname, and email in the request body. Returns a confirmation message and saves the data.
Submit your name, surname, and email. The server will remember… at least until you delete the file!
With Postman:
- Open Postman.
- Set the method to POST.
- Enter the URL:
http://localhost:8080/submit - Go to the Body tab, select raw, and choose JSON.
- Enter sample data:
{
"name": "Martin",
"surname": "West",
"email": "[email protected]"
}- Click Send.
- You should see a JSON response like:
{
"message": "Data received for user Martin West ([email protected]).",
"data": {
"name": "Martin",
"surname": "West",
"email": "[email protected]"
}
}With curl:
curl -X POST -H "Content-Type: application/json" -d '{"name": "Alice", "surname": "Blue", "email": "[email protected]"}' http://localhost:8080/submit
Lovingly crafted by Hanka Robovska
This project is licensed under the MIT License. See the LICENSE file for details.