Closed netsensei closed 1 year ago
I should be able to make API calls to an API endpoint available at api/v1 over https.
api/v1
This story details how to set this up using the OpenAPI specification
api/v1/person
go install -v github.com/ogen-go/ogen/cmd/ogen@latest
cd
openapi.yaml
api/v1/generate.go
go generate ./...
service.go
Service
Handler
oas_gen_server.go
repo
cmd/api.go
cmd_server.go
Initializing the API server:
// setup api apiServer, err := api.NewServer(api.NewService(repo)) if err != nil { return err }
Hooking the apiServer object in
apiServer
// mount api mux.Mount("/api/v1", http.StripPrefix("/api/v1", apiServer))
Documentation:
n/a/
Story
I should be able to make API calls to an API endpoint available at
api/v1
over https.This story details how to set this up using the OpenAPI specification
Success criteria
api/v1/person
, I get a JSON response with a person object.Implementation suggestion
go install -v github.com/ogen-go/ogen/cmd/ogen@latest
.api/v1
andcd
into it.openapi.yaml
.openapi.yaml
.api/v1/generate.go
from the OAI service to the directoryapi/v1
of the people service.go generate ./...
which will generate the server code for the API.service.go
file & implement aService
type:Handler
interface inoas_gen_server.go
repo
as a constructor argument.service.go
from the OAI service to see how this is implemented.cmd/api.go
as we do incmd_server.go
in the OAI service.Initializing the API server:
Hooking the
apiServer
object inDocumentation:
openapi.yaml
from the OAI service for another example.Automatic testing scenario
n/a/
Related issues
18