Hello Developers,
Building servers is the backbone of any application irrespective of its scale. At the heart of any web application is an HTTP Server - a crucial component responsible for consuming requests and generate desired responses over the internet.
Golang is a widely used server programming language and we can build fast, reliable and flexible HTTP Servers to help our web applications at scale. With this idea in mind, we have build turbo, a light weight router that can help you get started with minimal efforts.
Turbo - Readme Link
With the scope of this blog, we would be discussing on how to build a basic server using turbo and how to can provide configurations to the server.
Setup your project
1. Check your go environment
Ensure you have go installed
2. Create a new project
3. Initialise Go Module
You can keep the name of the module same as your project or you can select a custom. It will create a go.mod
file based on the module defined in the command
4. Install golly package
you would be required to install the golly package in order to use the turbo library
Your go.mod
file would like below
Start building a simple server using turbo
1. Create a Main Go file
2. Write your simple server following the instructions
A few things to note,
- Creating the router object,
turbo.NewRouter()
creates a new object and returns the object of the router - You use that router object and register your desired routes in your server. Multiple methods have been exposed and detailed explanation can be found in the turbo documentation.
3. Running your server
Running the server will generate the logs like below
You can see the list of registered routes on your server
4. Invoking your API
generates the following response
server is up and running
Contributing
- Any suggestions to improve the library are welcomed, we want this to be a community driven project and help it grow.
- If you feel any improvements in the package, feel free to raise the PR - Project
- If you find any bugs that we may have missed, feel free to raise the issues - Raise an Issue
- Looking forward to your contributions..
Project Details
This was a basic server registration and a simple GET endpoint implementation using turbo. There are a lot of customisations and features which we will discuss in the coming parts of turbo in the series.