I'm using go-swagger to generate the API server. I noticed that the json generated from swagger.yml is being kept in restapi/embedded_spec.go
.
What's the best way to expose that JSON spec so my ReactJS client can access it?
So far I've had to use swagger serve swagger.yml --port=50000
and point javacript client to localhost:50000/swagger.json
. I'm looking for a way to serve that JSON straight from restapi/embedded_spec.go
via my API.
Getting go-swagger First step is getting the swagger command line interface. If you already have go , use go get : go get -u -v github.com/go-swagger/go-swagger/cmd/swagger swagger --help Usage: swagger [OPTIONS] <command> Swagger tries to support you as best as possible when building APIs.
Go to http://localhost:8000/ in your address bar. This address lets you view the local web server. By default, web servers default to the index. html file in the directory, so it will show the Swagger UI file automatically.
From a browser, enter the URL to access the Swagger web page in the format https://<SnapCenter_IP_address_or_name>:8146/swagger/.
Maybe this is from an old code point of view, but currently when running a server the swagger.json
file is provided as well.
$ go run cmd/swagger-petstore-server/main.go --port=50000
2018/09/20 12:48:35 Serving swagger petstore at http://127.0.0.1:50000
$ curl http://127.0.0.1:50000/swagger.json
{
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With