Request Methods

Request methods are crucial indicators of the desired action to be executed on a resource. In Prisma PHP, they serve as the gateway to interacting with your application, enabling a spectrum of operations including data retrieval, resource creation, updating existing entities, and resource deletion. Selecting the correct request method for each operation is paramount to ensuring the robustness and security of your application.

Request Method Variables

Prisma PHP provides several variables that you can use to determine the request method and other request-related information.

These variables and functions are part of public functions, you can use them in any part of your application, all public functions are located in the settings/request-methods.php file.

  • $requestMethod: The request method used to access the resource (e.g., GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS).
  • $isGet: A boolean value indicating whether the request method is GET.
  • $isPost: A boolean value indicating whether the request method is POST.
  • $isPut: A boolean value indicating whether the request method is PUT.
  • $isDelete: A boolean value indicating whether the request method is DELETE.
  • $isPatch: A boolean value indicating whether the request method is PATCH.
  • $isHead: A boolean value indicating whether the request method is HEAD.
  • $isOptions: A boolean value indicating whether the request method is OPTIONS.
  • $isAjax: A boolean value indicating whether the request is an AJAX request.
  • $isWire: A boolean value indicating whether the request is a wire function request.
  • $contentType: The content type of the request body (e.g., application/json).
  • $requestedWith: The value of the X-Requested-With header in the request.
  • $protocol: The protocol used to access the resource (e.g., http, https).
  • $domainName: The domain name of the server.
  • $scriptName: The path to the current script.
  • $baseUrl: The base URL of the application, which points to the src/app directory of the application.
  • $documentUrl: The URL of the current document, which points to the document root / directory of the application.
  • $referer: The value of $_SERVER['HTTP_REFERER'], which represents the URL of the page that referred the current request.

By using these variables and functions, you can determine the request method and other request-related information in your Prisma PHP application and perform the appropriate actions based on the request method used by the client.

Request Method Examples

Here are some examples of how you can use request methods in Prisma PHP to interact with your application:

<php

  if ($isPost && isset($params->title)) {
      $todo = $prisma->todo->create([
          'data' => [
              'title' => $params->title
          ]
      ]);
      return $todo;
  }

  ?>