Testing RESTful Services, Part 1: Test Creation
Try it with a GUI tool first, then proper and more flexible test scripting in Ruby.
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