Testing and validating an API is hard because you don't always have control over the end points or who manages them.
- [Instructor] Alright, so what do you need to know to be successful in this course? First, you're going to need access to the documentation. For public APIs, this is usually something like developer dot website dot com. If it's an internal API, try to make sure you have the latest and most complete information. If your documentation is incomplete or wrong, or worse, it doesn't exist, you need to fix that first. Unfortunately, those issues are beyond the scope of this course. Next, you need basic familiarity with a library to make HTTP requests.
In the PHP world, this is probably Guzzle, though the curl extension and even the raw streams context can work too, though those can be more complicated than it's worth. Later, you may want to replace your raw HTTP library with a vendor-specific API library. That's completely acceptable. After all, some API companies and projects put out great SDKs, which can be embedded directly into your apps. Just remember that if you do that, you're not just testing the API, you're testing the SDK also.
That's not necessarily a problem, but when you hit an error or unexpected behavior, remember that it could be in one of two places now. Ideally, your API documentation has a list of all the applicable HTTP response codes, along with when they are relevant, but just in case they don't, knowing that response codes starting with 200 are successful and 400 are errors is sufficient for now. Finally, you need to have a good idea of the data you're going to get back. Hopefully sample data, both successes and failures, are included in the documentation.
If not, this becomes a little more challenging, but not impossible.
- The benefits of behavior testing
- Setting up a test environment
- Building your first API test
- Sending requests
- Validating response codes and payload
- Making authenticated requests
- Refactoring tests
- Writing to the API
- Establishing a system state for tests
- Using extensions
- Performing batch operations