{ DreamFactory: 'Blog' }

What if Chuck Norris Wanted to Create a Service That Automated APIs?

Posted by Erik Jacobsen

Mon, Apr 9, 2018

chuck_facts-467532-edited

Chuck Norris Joke Enthusiasts Trust DreamFactory to Automate  APIs

Thanks to amusing Chuck Norris API database site The Internet Chuck Norris Database, you can have some fun and keep the Chuck Norris jokes flowing.  With the help of DreamFactory and our API automation tools, you will always have life-changing insights making those around you just a bit more intelligent, good looking and successful.  Who doesn’t need to understand such nuggets as:

Contrary to popular belief, the Titanic didn't hit an iceberg. The ship was off course and ran into Chuck Norris while he was doing the backstroke across the Atlantic.

This post will show you how to create your own Swagger service definition, how to connect a few of the different endpoints so that you can come up with random jokes on the fly, or maybe have a couple of favorite jokes you like to use in watercooler banter.  Basically, DreamFactory was created out of fear that Chuck would be upset if someone didn’t come up with an easy way to automate his APIs.

First things first you want to create a new service to be able to bring in the jokes:

Image 2018-04-05 at 2.47.04 PM-529209-edited

Since this is a Remote Web Service, we will use the HTTP Service type. Chuck, being who he is, makes it very easy to get access to this content as I am sure he would put the fear of Norris into anyone who would want you to pass auth headers into the GET request.

On the Config Overview page, you just need to add in the base URL and you are ready to go:

Service Config OverviewAt this point, your service is live and you can start using the API endpoints through Postman, Insomnia and our built in tool: test_rest.html.  If using a 3rd party tool like the ones mentioned above, you will need the full base URL from your newly created service.

In this case, I have created a locally hosted Bitnami instance which is running on port 8080.  My custom URL would be: http://localhost:8080/api/v2/chuck_norris/.  Because we have created the service, we no longer need to add in the base URL from the ICNDB.  Our service name (in this case chuck_norris) incorporates the base URL from the 3rd party API we are trying to obtain information from.

When we look at test_rest.html, you can see the results, just not with fancy colors and formatting. You can see at the bottom of the screen the output in json format.

chuck norris test_rest.htmlSo - we can communicate with Chuck, but how do we make it even easier?  Swagger comes to our rescue here, using their swagger-ui javascript components to enable you to use our admin interface to interact with the API endpoints.  

Sidenote: If you have your own customized Swagger definition already created, and it is in the Swagger 2.0 definition, you can convert it to the current 3.0 standard with quite a few different tools.  Okay, let’s get building the Swagger service definition.

Swagger has a ton of tools, but I like using the online editor.  As you can see in the picture below, you can import files, URLs, etc.  For more information on any of the steps below check out their documentation.

Swagger 3.0 EditorYou will notice that the editor defaults to YAML (technically a subset of JSON), and DreamFactory supports the upload of YAML or JSON, so you have the freedom to create your service definition in either format.  Take a look at the screenshot below, which shows you the different ways you can upload or create your service definitions.

Service Definition Overview YAML/JSON

You can see examples of how to create YAML Swagger definitions here.  You can model your own swagger after this or by downloading another one of the native services in your DreamFactory install.  Just go to the API Docs tab and click the “Download Service Doc”. This will download the JSON version of the service doc for that particular service.  You can copy and paste, or upload it into the Swagger editor.

Download Service DocIn our case I have created a very basic example allowing us to just make some basic GET calls from the remote web service.  Here is what it will look like in the editor. Make sure your spacing is correct. I cannot tell you how many times I have thought everything was great, and the indents were off.  You will notice that you can also test your code right there in the editor before saving it and deploying it in your DreamFactory instance.

Swagger Editor API Call Test

OK, so once you feel good about your code, head back to DreamFactory and deploy that bad boy in your service definition and run it!  You should see the exact same results you saw in your editor tests.

API Docs GET Call Test Chuck Norris Random JokesNow go out there and make something great with DreamFactory and Swagger!  Thanks to ICNDB for creating this fun project. Make Chuck proud!! As always please reach out to us on on our social channels or drop us a line in the form below.

And remember: “Chuck Norris doesn’t do push ups. He does earth downs.”

 

Get started with DreamFactory with a free hosted DreamFactory development environment. Or, download and run it on the server, cloud, or desktop of your choice.

Remote Services Swagger OpenAPI Tutorials APIs API management HTTP Service

Weekly Digest

Recent Posts