Skip to content

Latest commit

 

History

History
72 lines (53 loc) · 1.93 KB

README.md

File metadata and controls

72 lines (53 loc) · 1.93 KB

ShiftAPI Logo

ShiftAPI

⚠️ This project is still in development, the API is not stable and is not ready for production use. ⚠️

Quickly write RESTful APIs in go with automatic openapi schema generation.

Inspired by the simplicity of FastAPI.

GolangCI Go Report Card

Installation

go get github.com/fcjr/shiftapi

Usage

    package main

    import (
        "context"
        "errors"
        "log"
        "net/http"

        "github.com/fcjr/shiftapi"
    )

    type Person struct {
        Name string `json:"name"`
    }

    type Greeting struct {
        Hello string `json:"hello"`
    }

    func greet(ctx context.Context, headers http.Header, person *Person) (*Greeting, error) {
        return &Greeting{
            Hello: person.Name,
        }, nil
    }

    func main() {
        ctx := context.Background()
        server := shiftapi.New(shiftapi.WithInfo(shiftapi.Info{
            Title: "Geeter Demo API",
            Description: "It greets you by name.",
        }))

        handleGreet := shiftapi.Post("/greet", greet)
        _ = server.Register(handleGreet) // You should handle errors in production code.

        log.Fatal(server.ListenAndServe(ctx, ":8080"))
        // redoc will be served at http://localhost:8080/docs
    }