codeception/module-rest
REST module for Codeception that simplifies testing REST/JSON APIs: send HTTP requests, set headers/auth, validate response codes, formats, and payloads, and assert JSON/XML content. Integrates with other Codeception modules for end-to-end API tests.
Begin by installing the module via Composer: composer require --dev codeception/module-rest. Then enable it in your acceptance.suite.yml or api.suite.yml (most common use case: API testing). In the config section, define the url of your API (e.g., http://localhost/api) and optionally set headers like Content-Type: application/json. The first test you write should be a simple GET request: use $I->sendGET('/users'); then verify response with $I->seeResponseCodeIs(200);. Check the Codeception module docs for up-to-date examples—this module complements Codeception’s PhpBrowser or Framework modules.
$I->amHttpAuthenticated($user, $pass) or inject tokens via $I->haveHttpHeader('Authorization', 'Bearer ' . $token).sendPOST(), sendPUT(), etc.—Codeception auto-serializes arrays to JSON when using application/json headers.seeResponseContains(), seeResponseCodeIs(), seeResponseIsJson(), and seeResponseJsonMatchesXpath() for flexible validation. For structured data, combine with grabDataFromResponseByJsonPath() to extract fields for chained assertions.REST module alongside Laravel6 or Framework modules in the same suite for integration testing. Configure REST to communicate with your app’s HTTP layer (not database directly), preserving realistic request flow.environment.yml) and route prefixes (/api/v1) to test multiple versions side-by-side.php-websocket-client) for non-HTTP protocols.seeResponseHeaderIs()) match lowercase keys (e.g., 'content-type', not 'Content-Type').['0' => 'x']) may be cast to indexed arrays—explicitly cast to objects or use json_encode() if strict key preservation is needed.debug: true in your suite config to log full requests/responses to stdout or your log file. Use seeHttpHeaderOnce() instead of seeHttpHeaderIs() when expecting duplicate headers (e.g., Set-Cookie).\Codeception\Module\REST in your own module to add project-specific helpers (e.g., loginAsAdmin(), createTestUserWithRole()).How can I help you explore Laravel packages today?