DeveloperBreeze

Filtering Development Tutorials, Guides & Insights

Unlock 2+ expert-curated filtering tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your filtering skills on DeveloperBreeze.

Building a Custom Pagination System for API Responses

Tutorial November 16, 2024
php

Modify the response structure to include metadata and links:

   use Illuminate\Http\Request;

   public function index(Request $request)
   {
       $posts = Post::paginate(10);

       return response()->json([
           'data' => $posts->items(), // The paginated items
           'meta' => [
               'current_page' => $posts->currentPage(),
               'per_page' => $posts->perPage(),
               'total' => $posts->total(),
               'last_page' => $posts->lastPage(),
           ],
           'links' => [
               'next' => $posts->nextPageUrl(),
               'previous' => $posts->previousPageUrl(),
           ],
       ]);
   }

REST API Cheatsheet: Comprehensive Guide with Examples

Cheatsheet August 24, 2024

Introduction

REST (Representational State Transfer) is an architectural style for designing networked applications. It relies on a stateless, client-server communication protocol, usually HTTP. RESTful APIs are widely used due to their simplicity and scalability. This comprehensive cheatsheet covers essential REST API principles and operations, complete with examples presented in HTML tables for easy reference.