Skip to content

BennettB123/simplehttp

Repository files navigation

simplehttp

A bare-bones HTTP/1.0 web framework for go.

Note: this package should not be used in a production environment. It was purely created as a learning opportunity to gain experience with go.

Documentation

Full documentation can be found on go's official documentation site at https://pkg.go.dev/github.com/BennettB123/simplehttp.

Features

✅ custom routing in the form of registering custom callbacks to be invoked when specific HTTP methods/paths are requested.
✅ handling multiple concurrent requests in parallel.
✅ methods to view information about incoming HTTP requests.
✅ convienent methods to modify HTTP responses.
✅ custom logger interface to receive messages about connections, incoming requests, and outgoing responses.

Basic Example

The following program will create a Server listening on port 8080. It will respond to incoming GET requests to the '/hello-world' path.

func main() {
	server := simplehttp.NewServer(8080)

	server.Get("/hello-world", func(req simplehttp.Request, res *simplehttp.Response) error {
		res.SetHtml("<h1>Hello, world!</h1>")
		return nil
	})

	err := server.Start()
	if err != nil {
		fmt.Println("There was an error starting the server:", err)
	}
}

See cmd/basicserver/basicserver.go for more examples.

About

A barebones HTTP web framework for go

Resources

License

Stars

Watchers

Forks

Packages

No packages published