Skip to content

Intervals API Documentation

Overview

The Intervals API is designed to facilitate the management of time intervals for various processes. It provides a structured approach to handling interval-based configurations, ensuring efficiency and consistency across applications. With this API, users can create, retrieve, update, and delete interval settings stored in a database. The following documentation outlines the available endpoints, expected request/response formats, and database schema.

Endpoints

Create Intervals Table

  • URL: /intervals/createTable
  • Method: POST
  • Description: Creates the intervals table if it does not already exist.
  • Response:
  • 200 OK: Table created successfully.
  • 400 Bad Request: Error creating the table.

Get All Intervals

  • URL: /intervals
  • Method: GET
  • Description: Retrieves all stored intervals.
  • Response:
  • 200 OK: Returns an array of interval objects.
  • 500 Internal Server Error: Database query error.
  • Example Response:
[
  {
    "id": 1,
    "intervalFeedbackTestApi": 5000,
    "intervalDeviceStatus": 10000,
    "intervalDeviceStatusEspera": 15000,
    "intervalAllDevices": 20000
  }
]

Get Interval by ID

  • URL: /intervals/:id
  • Method: GET
  • Description: Retrieves a specific interval by its ID.
  • Response:
  • 200 OK: Returns the requested interval.
  • 422 Unprocessable Entity: Invalid ID format.
  • 500 Internal Server Error: Database query error.
  • Example Response:
{
  "id": 1,
  "intervalFeedbackTestApi": 5000,
  "intervalDeviceStatus": 10000,
  "intervalDeviceStatusEspera": 15000,
  "intervalAllDevices": 20000
}

Create Interval

  • URL: /intervals
  • Method: POST
  • Description: Creates a new interval.
  • Request Body:
{
  "intervalFeedbackTestApi": 5000,
  "intervalDeviceStatus": 10000,
  "intervalDeviceStatusEspera": 15000,
  "intervalAllDevices": 20000
}
  • Response:
  • 200 OK: Interval created successfully.
  • 422 Unprocessable Entity: Invalid interval data.
  • 500 Internal Server Error: Database insertion error.

Update Interval by ID

  • URL: /intervals/:id
  • Method: PUT
  • Description: Updates a specific interval by its ID.
  • Request Body:
{
  "intervalFeedbackTestApi": 6000
}
  • Response:
  • 200 OK: Interval updated successfully.
  • 422 Unprocessable Entity: Invalid update information.
  • 500 Internal Server Error: Database update error.

Delete Interval by ID

  • URL: /intervals/:id
  • Method: DELETE
  • Description: Deletes a specific interval by its ID.
  • Response:
  • 200 OK: Interval deleted successfully.
  • 422 Unprocessable Entity: Invalid ID format.
  • 500 Internal Server Error: Database deletion error.

Example Usage

Fetch All Intervals using Axios

import axios from 'axios';

axios.get('/intervals')
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

Data Validation

All interval objects must include the following required fields:

  • intervalFeedbackTestApi
  • intervalDeviceStatus
  • intervalDeviceStatusEspera
  • intervalAllDevices
  • intervalDeviceWatchers
  • intervalDeviceWatchersTimeout
  • intervalRefreshToken
  • intervalDeviceInternalConsult
  • intervalDeviceSyncInfo

If any of these fields are missing or have an invalid format, the API will return a 422 Unprocessable Entity response.

Database Schema

The intervals table consists of the following fields:

CREATE TABLE IF NOT EXISTS intervals (
    id SERIAL PRIMARY KEY,
    intervalFeedbackTestApi BIGINT NOT NULL,
    intervalDeviceStatus BIGINT NOT NULL,
    intervalDeviceStatusEspera BIGINT NOT NULL,
    intervalAllDevices BIGINT NOT NULL,
    intervalDeviceWatchers BIGINT NOT NULL,
    intervalDeviceWatchersTimeout BIGINT NOT NULL,
    intervalRefreshToken BIGINT NOT NULL,
    intervalDeviceInternalConsult BIGINT NOT NULL,
    intervalDeviceSyncInfo BIGINT NOT NULL
);

Error Handling

  • 422 Unprocessable Entity: Invalid data format.
  • 500 Internal Server Error: Database errors.
  • 400 Bad Request: Issues with table creation or invalid parameters.

This documentation ensures a comprehensive understanding of how to interact with the Intervals API efficiently. 🚀