Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

Awesome Lists containing this project

README

        




Logo


Logo


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"))
}
```