go-api-with-swarg

command module
v0.0.0-...-068bbe7 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-api-with-swarg is:

Simple repo for writing an example of documenting an API with Swagger in Go

For running the server in the root path of the repository:

  • First run: swag init
  • Second run: go run ./main.go

Calling the API using Curl.

Thanks to swagger you don't need to think in all these commands that you'll see below. Because you can see them in the docs endpoint: http://localhost:3000/swagger

Get all element from Todo:

curl -X 'GET' \
  'http://localhost:3000/todo' \
  -H 'accept: application/json'

Get one element from Todo using Curl:

curl -X 'GET' \
  'http://localhost:3000/todo/2' \
  -H 'accept: application/json'

Create Todo example using Curl:

curl -X 'POST' \
  'http://localhost:3000/todo' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "id": "5",
  "task": "new item"
}'

Delete Todo example using Curl:

curl -X 'DELETE' \
  'http://localhost:3000/todo/5' \
  -H 'accept: application/json'

And remember every time you update the documentation you need to run swag init command. For more details, I'll write a post on my blog.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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