Design and Build Great Web APIs by Mike Amundsen

Design and Build Great Web APIs by Mike Amundsen

Author:Mike Amundsen
Language: eng
Format: epub, pdf
Tags: Pragmatic Bookshelf
Publisher: The Pragmatic Bookshelf, LLC


If you scroll up a bit, you’ll also notice that the editor UI displays a box showing a curl command-line example that calls the same endpoint. That should look something like this:

​ curl -X GET
​ "https://virtserver.swaggerhub.com/mamund/onboarding-master/1.0.0/"
​ -H "accept: application/prag+json"
​ -H "ETag: zaxscdvfbg"

When you execute that at the command line, you’ll get a response similar to the one shown in the UI screenshot shown earlier.

You can also test out write operations using the SwaggerHub mock service. It won’t really write any data to a server, but it will “mock” all the steps, including making sure you supply the proper arguments. A curl-ed version of the updateCompanyData action looks like this:

​ curl -X PUT
​ "https://virtserver.swaggerhub.com/.../1.0.0/wip/q1w2e3r4/company"
​ -H "accept: application/prag+json"
​ -H "If-Match: zaxscdvfbg"
​ -H "Content-Type: application/x-www-form-urlencoded"
​ -d "identifier=q1w2e3r4&companyName=SmithCo"

Note that, for the purposes of display in this book, I shortened the URL line (...) to make sure it fit on the page. You’ll also notice that the responses for all these tests are the same. The mock server just responds with the #/components/reply response defined within the OAS file.

Now that you know you can test the API using both the SwaggerHub editor interface and tools like curl, you have a working prototype you can use to test your ideas, show to others, and—when needed—modify the prototype to fix bugs and improve the interface in order to get it all set for the final work of the actual code-based implementation.

Before I wrap up this chapter, I want to cover one more thing you can do with OAS files: generate basic documentation for your API.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.