diff --git a/README.md b/README.md index 3e8263f..717efa0 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@ A simple Go-powered REST API kata. +## HTTP Server + +- KISS: Use built-in `http` package. https://gin-gonic.com/ looks cooler but also adds dozens of dependencies 😮 No need for a "fully-featured" web framework. + ## Swagger - Exposed at `http://localhost:8080/docs` diff --git a/docs/docs.go b/docs/docs.go index d6f6d7f..0db6e4d 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -38,6 +38,29 @@ const docTemplate = `{ } } } + }, + "/pokemon/{name}": { + "get": { + "produces": [ + "application/json" + ], + "summary": "Find a specific Pokemon by name", + "operationId": "get-specific-pokemon", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/pokemon.Pokemon" + } + }, + "500": { + "description": "error", + "schema": { + "type": "string" + } + } + } + } } }, "definitions": { diff --git a/docs/swagger.json b/docs/swagger.json index b9269cd..1d648c6 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -32,6 +32,29 @@ } } } + }, + "/pokemon/{name}": { + "get": { + "produces": [ + "application/json" + ], + "summary": "Find a specific Pokemon by name", + "operationId": "get-specific-pokemon", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/pokemon.Pokemon" + } + }, + "500": { + "description": "error", + "schema": { + "type": "string" + } + } + } + } } }, "definitions": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index bf9f9ec..9811a12 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -48,4 +48,19 @@ paths: schema: $ref: '#/definitions/pokemon.Pokemon' summary: get all Pokemon + /pokemon/{name}: + get: + operationId: get-specific-pokemon + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/pokemon.Pokemon' + "500": + description: error + schema: + type: string + summary: Find a specific Pokemon by name swagger: "2.0" diff --git a/pokemon/handler.go b/pokemon/handler.go index e0a09c9..dfbf2c0 100644 --- a/pokemon/handler.go +++ b/pokemon/handler.go @@ -7,6 +7,12 @@ import ( "pokedex/rest" ) +// @Summary Find a specific Pokemon by name +// @ID get-specific-pokemon +// @Produce json +// @Success 200 {object} Pokemon +// @failure 500 {string} string "error" +// @Router /pokemon/{name} [get] func HandleFindSingle(db *gorm.DB, rw http.ResponseWriter, req *http.Request) { repo := NewRepo(db) name := req.PathValue("name")