In this blog we will show how a WEB API created using Tapestry can be tested. Testing a web service is not straight forward as the PageTester, the default way of testing in Tapestry, doesn't allow for testing API. To overcome this difficulty we must start a Jetty server with custom/test web.xml. The test web.xml allows us to control the construction of objects. In this example we show how a mock service object can be inserted for testing, while using the full implementation for production.
This blog is part of a series of blogs on Tapestry that explains how to build a "simple" hello world example html page and expose the functionality of the page(s) via a WEB API. In a previous blog we showed how to setup a web API that responses in either XML or JSON. If you haven't read it yet, it's probably a good idea to have a look at this blog first before proceeding.
This blog picks things up from another previous blog in the series on testing page. The basic of testing a webpage generated with Tapestry are explained there. In this blog we will build on the code previously created.
In a previous blog in our Tapestry series we showed that Tapestry can be used as an API. While we would advice to do this only for simple cases, it could be a good solution if you wanted to offer Web API for your existing Tapestry application. If you were interested in a fully-fledged Web API with all the bells and whistles it would probably be better to use a separate framework.
In a previous blog we build an API returning JSON. This raises the question: is it also possible to return XML? The answer turns out to be yes!
In this blog we will show how to do so.
In this blog we will show you how to extend your Tapestry projects with a simple API. If you have a big project and need complex calls to expose your API functions, then this approach is not for you. Instead, if you have a couple of functions you would like to expose, this is a quick and simple approach to get it done.
- This tutorial uses Eclipse with Maven
- This tutorial builds on previous blog
We consider a setup where a request to \\example.com\api should be replied with a JSON stream, where stream is just fancy way of saying text file. To do this in Java there are a few very good frameworks:
The last one is the easiest complete-integration framework for REST API that will work with Tapestry that we could find. However, if your have very simple requirements even the out-of-the-box frameworks might not be worth configuring. The alternative is to parse arguments during the rendering of a page and respond with XML or JSON. In this example we’ll show how to create an API for our hello-world application, which we build in our previous blog. Continue reading