Forum Discussion

jg11's avatar
jg11
Visitor
7 years ago

Can I use localhost as host in swaggerhub?

Hi there - I'm new to swaggerhub so noob question alert!

 

Can I use swaggerhub (app.swaggerhub.com) to test out apis hosted on my localhost?  The CURL being generated by swaggerhub is perfect and works if I run it from git bash (I'm on windows). curl -X GET "http://localhost:57280/api/open" -H "accept: application/json".

 

However, when I click execute on swaggerhub it gives this error:

 

 content-length: 0  date: Sun, 11 Mar 2018 18:24:25 GMT  server: nginx/1.8.0 + Phusion Passenger 5.0.22  status: 403, 403 Forbidden  x-powered-by: Express, Phusion Passenger 5.0.22 

 

This leads me to believe that the URL is getting sent to swaggerhub's servers for resolution, and thus clearly localhost won't mean the same thing "over there".  Or is swaggerhub editor/UI an SPA which emits the URL locally to my browser such that it _could_ resolve properly, but I'm just doing something wrong?

 

CHeers!

 

JG

 

Full swagger ..

 

swagger: '2.0'
info:
version: '1.0'
title: 'Basic features of azure b2c'
description: 'Basic features of azure b2c'
host : 'localhost:57280'
basePath : '/api'
paths:
/open:
# In this operation we do not apply the security, because it was applied globally above.
# The security will be applied to this operation for that reason.
get:
summary: Server example operation
description: This is an example operation to show how security is applied to the call.
responses:
200:
description: OK
schemes:
- http

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi jg11,

     

    "Try it out" requests are proxied through SwaggerHub servers in order to bypass CORS restrictions in browsers. So, SwaggerHub needs the API server to be reachable over the public Internet. Localhost and local IPs are not supported as target servers.

     

    To test against localhost, you can load your API definition into standalone Swagger UI, e.g.:

    http://petstore.swagger.io/?url=https://api.swaggerhub.com/apis/{owner}/{name}/{version}

    and test the requests from there.

     

    Make sure to replace app.swaggerhub.com with api.swaggerhub.com in your API definition address in the link above.

    You may also need to enable CORS on your localhost in order for "try it out" to work.

     

    Also feel free to submit an enhancement request for SwaggerHub:
    https://community.smartbear.com/t5/SwaggerHub-Feature-Request/idb-p/SwaggerHubFeatureRequest