Testing with SRTs

Design and Build Great Web APIs — by Mike Amundsen (70 / 127)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 The Goals of API Testing | TOC | Using Postman for API Testing 👉

An easy way to start testing your API is to focus just on the interface itself with what I call simple request tests, or SRTs. SRTs are just what the name sounds like: a simple HTTP request you can run to validate that the minimal elements of the API are working as you would expect. And that’s how I use SRTs — to validate the API.

Here are a few examples of SRTs used for testing an API that supports managing people’s contact information:

ch09-testing/srt-requests.txt

​ # person api test requests
​ # 2020-02 mamund

http://localhost:8181/
http://localhost:8181/list/
http://localhost:8181/filter?status=active
http://localhost:8181/ -X POST -d \
​ id=q1w2e3r4&status=pending&email=test@example.org
http://localhost:8181/q1w2e3r4 -X PUT -d \
​ givenName=Mike&familyName=Mork&telephone=123-456-7890
http://localhost:8181/status/q1w2e3r4 -X PATCH -d status=active
http://localhost:8181/q1w2e3r4 -X DELETE

​ # EOF

I also used some SRTs very early in the book in Exploring APIs with curl.

Because HTTP APIs rely on URLs, HTTP methods, and a few HTTP headers, tools like curl give you all the power you need to create a collection of SRTs that you can run against your API. You can do this while you’re implementing the API as a…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.