go-rest

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2021 License: MIT

README

go-rest

Go Reference Coverage Status Github Action

go-rest is inspired by the REST API Tutorial. It will help to create a RESTful service with stdlib in go. It's considered to be stable, feature complete, and it will not receive any breaking changes.

One idea of the REST API Tutorial is to have "Wrapped Responses" ( see PDF page 21).

// Wrapped.Response

{
  "code": 200,
  "status": "success",
  "data": {
    // ...
  }
}

This package provides methods and helpers to render wrapped.Responses and to test them.

// Example Usage

package main

import (
	"net/http"

	"github.com/go-chi/chi/v5"

	"github.com/lanz-dev/go-rest/handler"
	"github.com/lanz-dev/go-rest/rest"
)

func main() {
	c := chi.NewMux() // go-rest doesn't depend on chi!
	c.Route("/api", func(r chi.Router) {
		r.NotFound(handler.NotFoundHandler)
		r.MethodNotAllowed(handler.MethodNotAllowedHandler)

		r.Get("/demo", func(w http.ResponseWriter, r *http.Request) {
			yourStructOrNil := "demo"
			rest.Ok(w, r, yourStructOrNil)
		})
	})
}

Directories

Path Synopsis
Package handler provides default handlers.
Package handler provides default handlers.
Package middleware providing middlewares.
Package middleware providing middlewares.
Package rest provides methods to render and to help implementing a REST api.
Package rest provides methods to render and to help implementing a REST api.
Package resttest provides helper methods for testing.
Package resttest provides helper methods for testing.
Package wrapped provides the wrapped.Response.
Package wrapped provides the wrapped.Response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL