POST / PUT / DELETE Requests

POST / PUT / DELETE Requests

When calling a POST / PUT / DELETE method, three pieces of information are required:

  1. The URL (This could also contain the query parameters)

  2. The authentication token

  3. The payload

These requirements also apply to PATCH requests.

POST Example:

/**
 * Test that the route /user/role returns 201
 *
 * @transaction auth
 * @test
 * @return void
 */
public function user_post_method_user_role_returns_201(): void
{
  $this->actingAsAdmin()
       ->authenticate()
       ->post('/user/role', [
          'organisation_id' => '1',
          'access_id' => '1',
       ]);
}
  1. The URL in this example is /user/role

  2. authenticate() authenticates the token

  3. The third piece of information is the payload.

PUT Example:

$this->actingAsAdmin()
     ->authenticate()
     ->put('/user/mobilenumber', [
          "number" => "1555".rand(100000,999999)
     ])
  1. The URL in this example is /user/mobilenumber

  2. authenticate() authenticates the token

  3. The third piece of information is the payload.

DELETE Example:

$this->actingAsAdmin()
     ->authenticate()
     ->delete('/courses/1', []);
  1. The URL in this example is /courses/1

  2. authenticate() authenticates the token

  3. The third piece of information is the payload.

Last updated