Custom Request Parameters

Created on 24 November, 2024Docs • 13 views • 2 minutes read

Pingtr allows you to create monitoring checks with custom HTTP requests, enabling you to test and monitor APIs, web services, or specific endpoints with precision.

This feature is crucial for ensuring your systems respond correctly to specific inputs, making it ideal for API developers, e-commerce platforms, and SaaS providers.

Why Custom HTTP Requests Are Important for Monitoring

Custom HTTP requests provide flexibility to simulate real-world use cases, ensuring your application or service performs as expected under various conditions. By customizing request methods, headers, bodies, and authentication, you can:

  1. Verify endpoint behavior with specific inputs.
  2. Check the availability and accuracy of API responses.
  3. Monitor endpoints with secured access using Basic Auth.
  4. Ensure proper handling of custom headers, like API keys or content types.

Key Aspects of Creating Custom HTTP Requests

When setting up a monitoring check with Pingtr, you can define the following elements:

1. Request Method

The HTTP method specifies the type of operation the request will perform.

  1. GET: Retrieve data from the server.
  2. POST: Send data to the server to create or update resources.
  3. PUT/PATCH: Update an existing resource.
  4. DELETE: Remove a resource.

Example Use Case: Monitor a payment gateway API by sending a POSTrequest with payment details and checking the response for success.

2. Request Body

The body of the HTTP request contains the data to be sent to the server. It is primarily used with POSTPUT, and PATCH methods.

Supported Formats:

  1. JSON
  2. XML
  3. Form Data

Example: For a POST request to an authentication API:

{
"username": "test_user",
"password": "secure_password"
}

3. Basic Authentication

Some APIs or endpoints require authentication to ensure secure access. With Basic Auth, you provide:

  1. Username
  2. Password

Example: To access a secured API:

  1. Username: admin
  2. Password: secure123

Headers will automatically include:

Authorization: Basic YWRtaW46c2VjdXJlMTIz

4. Custom Request Headers

Headers are metadata sent with a request to provide additional context or instructions. Custom headers can be used for:

  1. Content negotiation (Content-Type)
  2. Authentication (Authorization)
  3. API versioning or other custom purposes.

Example: For an API requiring an API key:

Content-Type: application/json
Authorization: Bearer <api_key>

Setting Up a Custom HTTP Request Monitoring Check in Pingtr

  1. Navigate to the Check Creation Page:
  2. Select the type of check you want to create (e.g., API check).
  3. Define Request Details:
  4. Choose the request method (GET, POST, etc.).
  5. Add the endpoint URL.
  6. Provide the request body if applicable.
  7. Input credentials for Basic Auth (if required).
  8. Add custom headers.
  9. Set Validation Rules:
  10. Define expected status codes (e.g., 200 OK).
  11. Specify response validation criteria like checking for specific text or JSON keys.
  12. Save and Activate the Check:
  13. Once the check is saved, Pingtr will begin monitoring the endpoint.

Examples of Monitoring Use Cases

Example 1: Monitor an API Endpoint

  1. Endpoint: https://api.example.com/login
  2. Method: POST
  3. Headers:
{
"Content-Type": "application/json"
}
  1. Body:
{
"username": "test_user",
"password": "secure_password"
}
  1. Validation:
  2. Status Code: 200
  3. Response contains: "success": true

Example 2: Monitor a Resource Deletion

  1. Endpoint: https://api.example.com/resource/12345
  2. Method: DELETE
  3. Headers:
{
"Authorization": "Bearer <api_key>"
}
  1. Validation:
  2. Status Code: 204
  3. Empty response body.

Example 3: Check API Response Time

  1. Endpoint: https://api.example.com/products
  2. Method: GET
  3. Headers:
{
"Accept": "application/json"
}
  1. Validation:
  2. Status Code: 200
  3. Response time under 500ms.

Tips for Effective Monitoring with Custom HTTP Requests

  1. Use realistic data in request bodies to simulate real-world scenarios.
  2. Regularly update headers and credentials to avoid expired tokens or outdated details.
  3. Combine response validation with performance monitoring for comprehensive checks.
  4. Leverage Pingtr's notification system to stay updated on any failures or performance issues.

By setting up custom HTTP requests in Pingtr, you can ensure your APIs and endpoints remain robust, secure, and performant.