Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Module Rest Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Auth-enabled endpoints: Use $I->amHttpAuthenticated($user, $pass) or inject tokens via $I->haveHttpHeader('Authorization', 'Bearer ' . $token).
  • Request bodies: For POST/PUT/PATCH, pass arrays or JSON strings directly to sendPOST(), sendPUT(), etc.—Codeception auto-serializes arrays to JSON when using application/json headers.
  • Response assertions: Leverage seeResponseContains(), seeResponseCodeIs(), seeResponseIsJson(), and seeResponseJsonMatchesXpath() for flexible validation. For structured data, combine with grabDataFromResponseByJsonPath() to extract fields for chained assertions.
  • Integration with Laravel/other frameworks: Use the 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.
  • API versioning: Use environment-specific URLs (environment.yml) and route prefixes (/api/v1) to test multiple versions side-by-side.

Gotchas and Tips

  • No built-in async support: REST module doesn’t handle WebSocket or SSE—use dedicated tools (e.g., php-websocket-client) for non-HTTP protocols.
  • Header case sensitivity: Codeception lowercases all header names internally—ensure your assertions (seeResponseHeaderIs()) match lowercase keys (e.g., 'content-type', not 'Content-Type').
  • JSON body parsing quirks: Sending an associative array with numeric keys (e.g., ['0' => 'x']) may be cast to indexed arrays—explicitly cast to objects or use json_encode() if strict key preservation is needed.
  • Debugging tips: Enable 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).
  • Extension point: You can extend \Codeception\Module\REST in your own module to add project-specific helpers (e.g., loginAsAdmin(), createTestUserWithRole()).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport