https://github.com/tiny-go/lite
Simple tool for building RESTful APIs
https://github.com/tiny-go/lite
api golang restful server
Last synced: 23 days ago
JSON representation
Simple tool for building RESTful APIs
- Host: GitHub
- URL: https://github.com/tiny-go/lite
- Owner: tiny-go
- License: mit
- Created: 2018-04-20T14:25:29.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-01-04T19:12:25.000Z (about 6 years ago)
- Last Synced: 2025-08-15T00:10:50.085Z (6 months ago)
- Topics: api, golang, restful, server
- Language: Go
- Homepage:
- Size: 64.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lite
[![GoDoc][godoc-badge]][godoc-link]
[![License][license-badge]][license-link]
[![Build Status][circleci-badge]][circleci-link]
[![Report Card][report-badge]][report-link]
[![GoCover][cover-badge]][cover-link]
Simple tool for building RESTful APIs
### Installation
```bash
go get -u github.com/tiny-go/lite
```
### Modules
You can use `BaseModule` that provides basic module functionality (such as register/unregister/list) or write your own implementation. `BaseModule` already contains `Register`, `Unregister` and `Controllers` methods and implements `Module` interface.
### Controllers
Any golang `func`, `struct` or custom type can be used as a controller provided that it implements `Controller` interface and has some action methods, such as `Get`/`GetAll`/`Post`/`PostAll`/... (check the entire list in `interfaces.go`).
### Dependencies
If you need to pass some dependencies (like config, database connection etc) to your module/controller use `handler.Map(dep)`, it will be passed to the module/controller (use struct tag ``inject:"true"`` in front of the struct fields that should be injected). Take a look at `example` folder for more information (for instance `example/auth/user/controller.go`).
### Usage
```go
package main
import (
"log"
"net/http"
"github.com/tiny-go/lite"
// register codecs
"github.com/tiny-go/codec/driver"
_ "github.com/tiny-go/codec/driver/json"
_ "github.com/tiny-go/codec/driver/xml"
)
func main() {
// set default codec
driver.Default("application/json")
// create new handler
handler := lite.NewHandler()
// map dependencies
handler.Map(depA)
handler.Map(depB)
handler.Map(depC)
// register modules
handler.Use(aliasOne, moduleA)
handler.Use(aliasTwo, moduleB)
// start HTTP server
log.Fatal(http.ListenAndServe(":8080", handler))
}
```
[godoc-badge]: https://godoc.org/github.com/tiny-go/lite?status.svg
[godoc-link]: https://godoc.org/github.com/tiny-go/lite
[license-badge]: https://img.shields.io/:license-MIT-green.svg
[license-link]: https://opensource.org/licenses/MIT
[circleci-badge]: https://circleci.com/gh/tiny-go/lite.svg?style=shield
[circleci-link]: https://circleci.com/gh/tiny-go/lite
[report-badge]: https://goreportcard.com/badge/github.com/tiny-go/lite
[report-link]: https://goreportcard.com/report/github.com/tiny-go/lite
[cover-badge]: https://gocover.io/_badge/github.com/tiny-go/lite
[cover-link]: https://gocover.io/github.com/tiny-go/lite