All Projects → sashabaranov → go-fastapi

sashabaranov / go-fastapi

Licence: Apache-2.0 license
Create an API and get Swagger definition for free

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-fastapi

gin-swagger
DRY templates for go-swagger
Stars: ✭ 79 (+3.95%)
Mutual labels:  openapi, gin
mattermost-api-reference
Mattermost API reference documentation.
Stars: ✭ 74 (-2.63%)
Mutual labels:  openapi
sanic-ext
Extended Sanic functionality
Stars: ✭ 26 (-65.79%)
Mutual labels:  openapi
swaggie
Tool for generating TypeScript services for given Swagger API endpoints
Stars: ✭ 18 (-76.32%)
Mutual labels:  openapi
mock-json-schema
Simple utility to mock example objects based on JSON schema definitions
Stars: ✭ 23 (-69.74%)
Mutual labels:  openapi
laya-template
服务基本框架,template
Stars: ✭ 13 (-82.89%)
Mutual labels:  gin
pink-lady
a template project of gin app.
Stars: ✭ 44 (-42.11%)
Mutual labels:  gin
openapi
OpenAPI 3 Specification for golang
Stars: ✭ 18 (-76.32%)
Mutual labels:  openapi
openapi-client
Generate ES6 or Typescript service integration code from an OpenAPI 2 spec
Stars: ✭ 92 (+21.05%)
Mutual labels:  openapi
ogen
OpenAPI v3 code generator for go
Stars: ✭ 436 (+473.68%)
Mutual labels:  openapi
oauth1-signer-ruby
Zero dependency library for generating a Mastercard API compliant OAuth signature.
Stars: ✭ 15 (-80.26%)
Mutual labels:  openapi
abap-openapi-client
ABAP OpenAPI Client and Server generator in ABAP
Stars: ✭ 44 (-42.11%)
Mutual labels:  openapi
restdocs-spec
A maven plugin for generating Open API and Postman Collection specifications using Spring Restdocs.
Stars: ✭ 43 (-43.42%)
Mutual labels:  openapi
openapi-types.ts
Generated TypeScript definitions based on GitHub's OpenAPI spec
Stars: ✭ 30 (-60.53%)
Mutual labels:  openapi
moko-network
Network components with codegeneration of rest api for mobile (android & ios) Kotlin Multiplatform development
Stars: ✭ 107 (+40.79%)
Mutual labels:  openapi
cookbook
VueJS + NodeJS Evergreen Cookbook
Stars: ✭ 440 (+478.95%)
Mutual labels:  openapi
sttp-openapi-generator
Generate sttp client from openapi specification with ease!
Stars: ✭ 26 (-65.79%)
Mutual labels:  openapi
gmsec
golang micro service base on gin. golang 微服务集成框架
Stars: ✭ 141 (+85.53%)
Mutual labels:  gin
go-saas
go data framework for saas(multi-tenancy)
Stars: ✭ 101 (+32.89%)
Mutual labels:  gin
swagger-converter
OpenAPI/Swagger 2.0 to OpenAPI 3.0 Converter WebService
Stars: ✭ 58 (-23.68%)
Mutual labels:  openapi

go-fastapi

Go Reference Go Report Card

go-fastapi is a library to quickly build APIs. It is inspired by Python's popular FastAPI library.

Features:

  • Auto-generated OpenAPI/Swagger schema without any markup
  • Declare handlers using types, not just Context
  • Based on gin framework

Installation: go get github.com/sashabaranov/go-fastapi

Example

package main

import (
	"github.com/gin-gonic/gin"
	"github.com/sashabaranov/go-fastapi"
)

type EchoInput struct {
	Phrase string `json:"phrase"`
}

type EchoOutput struct {
	OriginalInput EchoInput `json:"original_input"`
}

func EchoHandler(ctx *gin.Context, in EchoInput) (out EchoOutput, err error) {
	out.OriginalInput = in
	return
}

func main() {
	r := gin.Default()

	myRouter := fastapi.NewRouter()
	myRouter.AddCall("/echo", EchoHandler)

	r.POST("/api/*path", myRouter.GinHandler) // must have *path parameter
	r.Run()
}

// Try it:
//     $ curl -H "Content-Type: application/json" -X POST --data '{"phrase": "hello"}' localhost:8080/api/echo
//     {"response":{"original_input":{"phrase":"hello"}}}

To generate OpenAPI/Swagger schema:

myRouter := fastapi.NewRouter()
myRouter.AddCall("/echo", EchoHandler)

swagger := myRouter.EmitOpenAPIDefinition()
swagger.Info.Title = "My awesome API"
jsonBytes, _ := json.MarshalIndent(swagger, "", "    ")
fmt.Println(string(jsonBytes))

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].