Testing RESTful Services, Part 1: Test Creation
Try it with a GUI tool first, then proper and more flexible test scripting in Ruby.
--
A repost of my daughter’s article with permission. I added a few notes. The scripts are based on my book: API Testing Recipes in Ruby.
Update: Part 2: Run frequently in a Continuous Testing Server.
RESTful web services are based on the Representational State Transfer (REST) architecture. In a RESTful service, payloads are in some uniform format (e.g. JSON, HTML, XML, etc), via HTTP.
I will use a sample REST service site, Thomas Bayer, for examples to test typical RESTful services: LIST, READ, CREATE, UPDATE and DELETE records.
Table of Contents:
∘ My API Testing Approach
· LIST all records
· READ a record
· CREATE a new record
· UPDATE a record
· DELETE a record
· Review (Zhimin)
My API Testing Approach
Here’s how I write API tests (including SOAP, REST and others):
- Try the request in a GUI API tool (like Postman, Paw, etc), which can view request data and response data in a user-friendly way.
- Once request data and endpoint details have been confirmed, I will write the test in Ruby. The benefits are being more flexible, reusable and easier to run in a CI/CD pipeline.
We can use HTTP test applications such as Postman and Paw (macOS only) to invoke REST API calls. I prefer Paw for simplicity, which is like old Postman.
Zhimin: New Postman offers more features; hence, more complex. Many Postman’s new feature, IMO, can be handled better in scripting languages.
LIST all records
HTTP Method: GET
URL: http://thomas-bayer.com/sqlrest/CUSTOMER
In Paw
In Ruby