Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jesperkha/topaz
Bare bones wrapper for Go http. Making a simple backend easy and quick to set up.
https://github.com/jesperkha/topaz
backend easy-to-use golang server simple
Last synced: 3 days ago
JSON representation
Bare bones wrapper for Go http. Making a simple backend easy and quick to set up.
- Host: GitHub
- URL: https://github.com/jesperkha/topaz
- Owner: jesperkha
- Created: 2022-03-20T21:01:26.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-20T22:42:29.000Z (over 2 years ago)
- Last Synced: 2024-11-08T17:16:25.248Z (about 2 months ago)
- Topics: backend, easy-to-use, golang, server, simple
- Language: Go
- Homepage:
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Simplified HTTP server package. Lets you set up
a web server in minimal time.
## Installation
```console
$ go get github.com/jesperkha/topaz
```
## Example
```go
...type user struct {
id string
}func main() {
server := topaz.NewServer()// Serve a static directory
server.Static("/", "pages")// Example of a handler to create a new user json object with a given id
server.Get("/create/:id", func(req topaz.Request, res topaz.Response) {
// Gets the id value from the URL
userId := req.Param("id")
newUser := user{id: userId}// Send back data as JSON
if err := res.JSON(newUser); err != nil {
res.Status(500)
}// If a status is not set 200 is assumed
})// Will serve to localhost:3000 unless the PORT env variable is set
server.Listen(server.EnvPort(":3000"))
}
```