Skip to content

KarthiKeyan05046/API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

API Response Documentation

This document outlines the expected response formats for successful and error responses from the API.

Response Schema

The API responses follow a common schema:

Successful Responses

There are two main types of successful responses: with pagination and without pagination. Both responses share a common structure with slight variations.

1. With Pagination

{
  "status": 200,
  "message": "success",
  "data": {
    "products": [
      {
        "id": 1,
        "name": "Product A",
        "price": 10.99
      },
      {
        "id": 2,
        "name": "Product B",
        "price": 15.5
      },
      {
        "id": 3,
        "name": "Product C",
        "price": 7.25
      }
    ],
    "meta": {
      "current_page": 1,
      "per_page": 3,
      "total_pages": 10,
      "total_count": 30
    }
  },
  "errors": {}
}

2. Without Pagination

{
  "status": 200,
  "message": "Product created sucessfully",
  "data": {
    "product": {
      "id": 1,
      "name": "Product A",
      "price": 10.99
    }
  },
  "errors": {}
}

Error Response:

1. General

{
  "status": 400,
  "message": "Validation failed",
  "errors": {
    "name": [
      "Name cannot be empty"
    ],
    "price": [
      "Price must be a number"
    ]
  },
  "data": {}
}

1. Unauthorized Request

{
  "status": 401,
  "message": "You are not authorized to access this resource. Please login or check your credentials."
}

API BEST PRACTICES

REST API Design Best Practices Medium Blog

API Design 101: From Basics to Best Practices

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors