Testing RESTful Services, Part 1: Test Creation

Try it with a GUI tool first, then proper and more flexible test scripting in Ruby.

Zhimin Zhan
6 min readJul 26, 2022

--

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):

  1. 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.
  2. 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

--

--

Zhimin Zhan

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.