How to debug RESTful services? [closed] - debugging

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm looking for an easy way to debug RESTful services. For example, most webapps can be debugged using your average web browser. Unfortunately that same browser won't allow me to test HTTP PUT, DELETE, and to a certain degree even HTTP POST.
I am not looking to automate tests. I'd like to run new services through a quick sanity check, ideally without having to writing my own client.

Use an existing 'REST client' tool that makes it easy to inspect the requests and responses, like RESTClient.

At my firm we use a variety of different tools and approaches to testing RESTful services:
We write cURL scripts - essentially a single command saved in a file. One file per resource per method. For PUT and POST, we'll usually have files containing the representations to send alongside the cURL script. For example, for a mailbox resource, we might have a file named mailbox_post.cmd, which might contain the line curl -v -X POST -u username -H 'Content-Type:application/xml' -d #mailbox_post.xml http://service/mailbox. We like this approach because we end up building a collection of tests which can be run in a batch, or at least passed around between testers, and used for regression testing.
We use cURL and RESTClient for ad-hoc tests
We have the service serve XHTML by default, so it's browsable, and add forms resources, so the service is actually partially or fully testable using a browser. This was partly inspired by some parts of RESTful Web Services, wherein the authors show that the line between web services and web applications may not need to be as solid and strict as is usually assumed.
We write functional tests as Groovy closures, using the Restlet framework, and run the tests with a test runner Groovy script. This is useful because the tests can be stateful, build on each other, and share variables, when appropriate. We find Restlet's API to be simple and intuitive, and so easy to write quick HTTP requests and test the responses, and it's even easier when used in Groovy. (I hope to share this technique, including the test runner script, on our blog soon.)

Postman, a Google Chrome extension, may be helpful.
Edit years later: Also the website of the url in case Chrome extension link gets changed: www.postman.com

I've found RequestBin useful for debugging REST requests. Post to a unique URL and request data are updated/displayed. Can help in a pinch when other tools are not available.
https://requestbin.com/

A tool I've found useful if you're running OS X Leopard:
HTTP Client
It's a very simple GUI program that allows you to craft http requests to a resource and view the response.

cURL works just fine.

You can use fiddler's Composer to debug restful services..
Updated JD 12 sep 2013: Rest Builder is now called Composer.

I ended up settling on POSTMAN
It supports all REST features I could think of, and the UI is absolutely excellent. The only downside is that it requires Chrome.

RESTTest for Firefox (an add-on). Fiddler for IE.

I'm using Soap UI to test my REST API.
It is more complete than any other tools:
fine debug requests and responses
automated testing
all GUI based
properties and properties transfer to parameterize your tests
conditional testing
performance testing
I'm not working for SmartBear.
I was already a big fan of SoapUI while using it for SOAP WebServices.

Aside from using one of the tools in Peter Hilton's response, I would have to say that scripting the tests with LWP or some similar tool may be your only option. You could bypass the use of LWP by just opening a socket, sending a raw HTTP request in and examining what you get in return. But as far as I know, there are a dearth of testing tools for this sort of domain-- most look at this problem-space primarily from the lens of a web-site developer, and for them the browser is enough of a testing platform.

I use restclient, available from Google Code. It's a simple Java Swing application which supports all HTTP methods, and allows you full control over the HTTP headers, conneg, etc.

If you want free tool for the same purpose with additional feature of multipart form data submission it is here http://code.google.com/a/eclipselabs.org/p/restclient-tool/

Firefox's has RESTClient plug-in to send different request with methods, parameters, headers etc.

You guys should check poster extension for firefox, it's simple and useful enough to use :)

I tend to write unit tests for RESTful resources using Jersey which comes with a nice REST client. The nice thing is if you implement your RESTful resources using JAX-RS then the Jersey client can reuse the entity providers such as for JAXB/XML/JSON/Atom and so forth - so you can reuse the same objects on the server side as you use on the client side unit test.
For example here is a unit test case from the Apache Camel project which looks up XML payloads from a RESTful resource (using the JAXB object Endpoints). The resource(uri) method is defined in this base class which just uses the Jersey client API.
e.g.
clientConfig = new DefaultClientConfig();
client = Client.create(clientConfig);
resource = client.resource("http://localhost:8080");
// lets get the XML as a String
String text = resource("foo").accept("application/xml").get(String.class);

because its totally missing here:
https://luckymarmot.com/paw
Is worth ever penny...

Related

How to perform an Load Test/Performance Test with Vaadin 10 with JMeter

I work on a Vaadin 10 project and we want to perform a load test on our website. Before we used Vaadin 10, we could do that with Jmeter but with Vaadin 10 it seems that JMeter doesn't work.
We tried using JMeter 5.1.1 and recorded the test case. The first problem was the CSRF token and the push id. Both could get extracted with a regular expression extractor and we put them in the body data:
{"csrfToken":"${csrf}","rpc": [{"type":"mSync","node":5,"feature":1,"property":"invalid","value":true}]," syncId":0,"clientId":0}
As far as I can see, at least that worked, but the only result we get back is a HTML page with "You have to enable javascript in your browser to use this web site."
Does anyone know if there are better ways to perform a load test on a Vaadin 10 application or how to get it working with JMeter?
Most answers I found until now are for Vaadin 8 or 7, but none for Vaadin 10+.
Yes, it is possible to use JMeter for load test Vaadin 10+ applications. You should be able to use following regex for extracting the csrf token:
Vaadin-Security-Key":"(.+?)"
A screenshot of my JMeter when testing against Vaadin 13 Bakery app starter:
In addition to JMeter, Gatling is also a good option when scalability testing Vaadin (any version) applications. There is a quite good example Gatling test script in Bakery App starter for Vaadin 13: https://vaadin.com/start/latest/full-stack-spring See the path: \src\test\scala\BaristaFlow.scala of the project.
Edit:
I uploaded a small but fully functioning JMeter test against V13 application (the same Bakery Flow starter) here: https://gist.github.com/johannest/593309e31e35789f8e5b03bed074f13c
The example script shows the csrf token extract, but also how to extract component ids (such as an id used for the "New" button) and client and sync ids. Extracting these ids and using them as variables in the following requests (instead of using recorded ids) makes your test more stable.
I postet this question a time ago since some people have intresst in this Question i will post some informations how we dealed with the situation.
our application didnt want to work with J-Meter it should be possible with jmeter but i did not manage to get it to an working state
we used neoLoad(the trail version was sufficient for our use case) and neoload was easy to use for Vaadin 10
but i cant give detailed informations how to use neoLoad with vaadin 10 but maybe someone can use this information to shorten the research time

Is there any way to start with a POST request using Selenide

I'm trying to start a Selenide test with a POST request to my application.
Instead of a simple open(/startpoint)
I would like to do something like open(/startpoint, stuff=foo,stuff2=bar)
Is there any way to do that?
I'm asking this because the original page which posts to this start point depends on external providers that are often offline (development environment) and so will often fail too early (and are not the subject of the test)
No, Selenium doesn't have the ability to do a POST request, unless you loaded a dummy HTML page with a <form> tag on it (as a unit test) and a submit button (such as src/test/resources/FormPage.html). So, the alternative is to build a HTTP post query from scratch using Apache HttpUtils library. I usually use the latter method (as an integration test), although the former would work I think.

ProtocolViolationException Load testing web service (GET action with content-body)

I created an ASP.NET MVC4 Web API service (REST) with a single GET action. The action currently needs 11 input values, so rather than passing all of those values in the URL, I opted to encapsulate those values into a single class type and have it passed as Content-Body. When I test in Fiddler, I specify the verb as GET, and enter the JSON text in the "Request Body" input box. This works great!
The problem is when I attempt to perform Load Testing in Visual Studio 2010 Ultimate. I am able to specify the GET action and the JSON Content-Body just fine. But when I run the Load test, VS reports exceptions of type ProtocolViolationException (Cannot send a content-body with this verb-type) in the test results. The test executes in 1ms so I suspect the exceptions are causing the test to immediately abort. What can I do to avoid those exceptions? I'd prefer to not change my API to use URL arguments just to work-around the test tooling. If I should change the API for other reasons, let me know. Thanks!
I found it easier to put this answer rather than carry on the discussions.
Sending content with GET is not defined in RFC 2616 yet it has not been prohibited. So as far as the spec is concerned we are in a territory that we have to make our judgement.
GET is canonically used to get a resource. So you are retrieving this resource using this verb with the parameters you are sending. Since GET is both safe and idempotent, it is ideal for caching. Caching usually takes place based on the resource URI - and sometimes based on various headers. The point is cache implementations - AFAIK - would not use the GET content (and to be honest I have not seen any GET with content in real world). And it would not make sense to include the content in the key generation since it reduces the scalability of the caches.
If you have parameters to send, they must be in the URI since this is part of what defines that URI. As such, I strongly believe sending content with GET is wrong.
Even when you look at implementations such as OData, they put the criteria in the URI. I cannot imagine your (or any) applications requirements is beyond OData query requirements.

vcr with capybara-webkit

I'm using capybara-webkit to test integration with a third party website (I need javascript).
I want to use vcr to record requests made during the integration test but capybara-webkit doesn't go over net http so vcr is unable to record them. How would I go about writing an adaptor for vcr that would allow me to record the reqeusts?
Unfortunately, VCR is very much incompatible with capybara-webkit. The fact is that capybara webkit is using webkit, which is in c. Webmock and Fakeweb, which are the basis for VCR, can only be used for Ruby web requests. Making the two work together would likely be a monumental task.
I've solved this problem two ways:
The first (hacky, but valid) is to add a new javascript file to the application that is only included in the test environment. This file stubs out the JS classes which make external web requests. Aside from the pure hackatude of this approach, it requires that every time a new request is added or changed you must change the stubs as well.
The second approach is to route all external requests through my own server, effectively proxying all external requests through my server. This has the huge disadvantage that you have to have an action for everything you want to consume (you could genericize it, with some work). It also suffers from the fact that it could as much as double the time for the request to complete. However, since the requests are now being made by Ruby you can use VCR in all it's glory.
In my situations, approach #2 has been much more to my advantage thanks to the fact that I need ruby to manipulate the data so that I can keep my javascript source-agnostic. I was, however, using approach #1 for quite a while successfully.
I've written a small ruby library (puffing-billy) for rspec+capybara that does exactly this -- it injects a proxy in between your browser and the outside world and allows you to fake responses to specific requests.
Example:
describe 'fetching badges from stackoverflow API' do
it 'should show a nice message when you have no badges' do
# stub some JSONP
proxy.stub('http://api.stackoverflow.com/1.1/users/1/badges',
:jsonp => { :badges => [] })
visit '/my_badges'
page.should have_content("You don't have any badges :(")
end
end

How do I test a Curl based FaceBook API implementation?

I wrote my own FaceBook library that uses actual Curl requests, not libcurl.
Is there a way to test it? I'm asking this because most solutions involve using something like fakeweb which as far as I can tell will not work here.
The existing code can be found on my github page.
One approach would be to use a different host/port in test mode (eg localhost:12345)
Then in your test run a sinatra or webrick servlet on that port that you configure to respond to the requests your code should be making
You could mock Request.dispatcher with an expected behavior, pretty much like Fakeweb would do.
There are a few examples on this file, specially https://github.com/chrisk/fakeweb/blob/master/lib/fake_web/ext/net_http.rb#L44.
When running your tests/specs, monkey-patch the run method of your Request class to hook into the Marston VCR library. See the existing library_hooks subdir for examples and ideas on how to do this -- the fakeweb implementation is a good place to start.
VCR works well with live services like Facebook's because it captures interactions "as is", and VCRs can be easily re-recorded when the services change.
I'm running into problems with your library, however. You need to require the cgi and json libraries; it also looks like it requires a Rails environment (it's failing to find with_indifferent_access on Hash).

Resources