Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ricpalomino/spring-boot/llms.txt

Use this file to discover all available pages before exploring further.

Every endpoint in this API returns a response wrapped in ApiResponse<T> — a lightweight generic envelope that gives you a consistent structure to parse regardless of which operation you call. The envelope carries an HTTP status code as a string, a human-readable message, and the actual payload in the data field. Having a single predictable shape means you can write one response-handling routine and reuse it across all endpoints: check responseCode, read the message if needed, and extract data when the operation succeeded.
responseCode mirrors the HTTP status code of the response (for example, "200", "201", "404"). You can use it for programmatic error handling even in environments where the raw HTTP status is discarded, such as some API gateway integrations or frontend fetch wrappers that resolve all responses regardless of status.

Source code

ApiResponse.java
package com.zegel.springboot.response;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class ApiResponse<T> {

    private String responseCode;
    private String responseMessage;
    private T data;

    public ApiResponse(String responseCode, String responseMessage, T data) {
        this.responseCode = responseCode;
        this.responseMessage = responseMessage;
        this.data = data;
    }

    public ApiResponse(String responseCode, String responseMessage) {
        this.responseCode = responseCode;
        this.responseMessage = responseMessage;
    }

}

Fields

responseCode
string
required
The HTTP status code represented as a string — for example "200", "201", "400", "404", or "500". Always present in every response.
responseMessage
string
required
A human-readable description of the outcome. Provides context for both successful operations and errors.
data
T | null
The actual response payload. The concrete type depends on the endpoint that was called. Set to null for error responses that carry no payload.

JSON examples by scenario

Success — list of products

GET /api/v1/products — 200
{
  "responseCode": "200",
  "responseMessage": "Productos obtenidos correctamente",
  "data": [
    { "id": 1, "name": "Laptop Pro 15", "price": 1299.99 },
    { "id": 2, "name": "Wireless Mouse", "price": 29.99 }
  ]
}

Success — single product

GET /api/v1/products/{id} — 200
{
  "responseCode": "200",
  "responseMessage": "Producto obtenido correctamente",
  "data": {
    "id": 1,
    "name": "Laptop Pro 15",
    "price": 1299.99
  }
}

Created

POST /api/v1/products — 201
{
  "responseCode": "201",
  "responseMessage": "Producto creado correctamente",
  "data": {
    "id": 3,
    "name": "USB-C Hub",
    "price": 49.99
  }
}

Not found

GET /api/v1/products/{id} — 404
{
  "responseCode": "404",
  "responseMessage": "Producto no encontrado con ID: 99",
  "data": null
}

Validation error

When the request body fails constraint validation, the data field contains a map of field names to error messages.
POST /api/v1/products — 400
{
  "responseCode": "400",
  "responseMessage": "Error de validación",
  "data": {
    "name": "El nombre del producto debe tener entre 3 y 100 caracteres",
    "price": "El precio del producto debe ser mayor a 0"
  }
}

Server error

500
{
  "responseCode": "500",
  "responseMessage": "Ocurrió un error en el servidor",
  "data": null
}

Build docs developers (and LLMs) love