Thursday 12 May 2016

Leverage Github Pages to simulate REST Service (HTTP GET)

In this article, I shall talk and demonstrate about leveraging github page to be used as REST service simulator. 
Most of the developers in typical development cycle shall be implementing the solution in bits and pieces. We would be having dependencies on other network services (REST APIs). This article shall be useful for those
  • blocked on other's service implementation that is either in development or not yet started
  • All they need is a simple HTTP GET service (You could pass query parameters and headers as well !!)
  • Need some sample test data (let it be static for now. As such for testing purpose, its fine)
  • Need to test their integration over and beyond intranet


Most of you must already be knowing that Github pages allows you to host webpages. This is possible by creating a special repository with the name '<github-id>.github.io' in your git account and placing the relevant HTML/CSS. I had explored this and could create mine like most of you have already done.

I have figured out that github can as well be used as a API hosting server. Of course, with little caveats, I could simulate a HTTP GET REST service. Refer my test rest service here. To test it, hit the URL http://balaji-katika.github.io/test.json using any API testing tool like curl, PostMan etc.,
All you need is to do is to create a file with .json suffix. Access with any API testing tool  Thats it !! You are done. 

FAQs

* I could as well, build this kind of simulation using a simple spring based webapp samples running on my localhost. How is it different ?
Well, you can. However, this trick might benefit when you want to access the API outside the company intranet. Further, no headache of maintaining/build the new localhost based service when all you can do is to simple create a file with test data. Isn’t it ?

* What are the caveats you talked above ?
You cannot access this endpoint from a web application. Since, browser respect CORS headers and shall prohibit your application from hitting this endpoint

* What kind of tools/apps can benefit out of this ?
Any application (except for javascript, jsp based) planning to pull data from remote service could use this technique.

* Can you demo a real world application to help me understand better.

In the next article, I shall talk about how I could leverage this in one my hobby android application. 

No comments:

Post a Comment