GitHubLaravelPHP

Laravel Healthcare API — A Complete RESTful Example with Services, Policies & Swagger

Healthcare API is a Laravel 12 RESTful backend demonstrating a clean, production-grade approach to appointment booking and cancellation. It follows service pattern, implicit route model binding, and policy-based authorization for secure access control.

GitHub – Healthcare API Repository https://github.com/sachin-sanchania/healthcare-api

Key Features of Healthcare API

  • Laravel 12, PHP 8.1+ : Built with the latest framework conventions and tooling.
  • Service Pattern : Business logic lives in app/Services, keeping controllers slim and testable.
  • Policy Authorization : Sensitive actions (e.g., cancel appointment) are guarded by policies.
  • Implicit Route Model Binding : Clean, readable routes with automatic model resolution.
  • Swagger UI : Auto-generated, interactive API docs at /api/documentation once the app runs.
  • Seeded Demo User : Ready-to-test login out of the box.

Prerequisites

  • PHP 8.1 or higher
  • Composer
  • MySQL (or compatible)
  • Git

1) Clone the Repository & install

git clone https://github.com/sachin-sanchania/healthcare-api.git 
cd healthcare-api

2) Install Dependencies

composer install 

3) Setup Environment File

cp .env.example .env

After copying the .env file, open it in a text editor and update your MySQL database configuration:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_user
DB_PASSWORD=your_database_password

4) Generate Application Key

php artisan key:generate

5) Run Migrations and seeders

php artisan migrate --seed

6) Serve the Application

php artisan serve

The application will be available at: http://localhost:8000

7) API Documentation [Swagger Implementation]

After successfully running the project, you can check the interactive API documentation in your browser at /api/documentation, which will display the Swagger UI with all your annotated API endpoints.

8) Login Credentials for Generating Login Token

You can use the following credentials to log in and generate tokens for the seeded user:

  • Email: johndoe@example.com
  • Password: 12345678

Core Endpoints

The exact list depends on your routes/api.php. Below are examples reflected in the README.

  • POST       |       /api/login                                |     Authenticate and get token
  • GET          |      /api/professionals                 |     List healthcare professionals
  • POST       |     /api/appointment/book       |     Book an appointment

Project Structure

  • app/Services/– Core business logic
  • app/Policies/ – Authorization logic
  • app/Providers/ – Custom Service Providers. For eg. Exception Handler
  • routes/api.php  – API route definitions
  • app/Http/Requests/ – Request validation
  • app/Http/Controllers/ – HTTP layer controllers

Conclusion

The Healthcare API showcases a maintainable Laravel architecture for healthcare-style bookings and cancellations. With Services + Policies, implicit binding, and Swagger, it’s an ideal foundation for real projects or portfolio work.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button