Code Monkey home page Code Monkey logo

laravel-api-boilerplate's Introduction

Laravel API Boilerplate with Authentication and Media Support

This repository contains a boilerplate for a Laravel-based API project, complete with built-in authentication and extensive support for media and image handling. This boilerplate is designed to kickstart your API development, allowing you to focus on building unique features rather than setting up the basic structure.

Features

  • Laravel 8.1: Built on the latest version of Laravel (as of this writing).
  • JWT Authentication: JSON Web Token (JWT) based authentication out of the box.
  • Media & Image Handling: Integrated support for media upload, storage, and image manipulation.
  • RESTful API Structure: Predefined structure for creating RESTful endpoints.
  • Database Migrations & Seeders: Basic user table migration and seeders for quick setup.
  • API Rate Limiting: Configurable rate limits for your API endpoints.
  • CORS Support: Cross-Origin Resource Sharing (CORS) enabled for API routes.
  • Testing: Basic setup for API testing with PHPUnit.
  • API Documentation: Starter template for API documentation.
  • Environment Configuration: DotEnv for easy environment configuration.

Requirements

  • PHP >= 8.0
  • Composer
  • MySQL or any other Laravel supported database system
  • (Optional) Postman or any API testing tool

Installation

  1. Clone the Repository

    git clone https://github.com/your-username/your-laravel-api-boilerplate.git
    cd your-laravel-api-boilerplate
  2. Install Dependencies

    composer install
  3. Environment Setup

    • Copy .env.example to .env and configure your database and other settings.

    • Generate an application key:

      php artisan key:generate
  4. Docker Environment Setup with Laravel Sail

    • If you do not have Docker installed, follow the official Docker installation guide.

    • Start the Docker environment using Laravel Sail. This command will build your Docker containers and start the services defined in your docker-compose.yml file:

      ./vendor/bin/sail up
    • Note: On first run, Sail's application containers will be built on your machine. This could take several minutes.

  5. Database Migration and Seeding (with Sail)

    • Once the Docker environment is up and running, use the following Sail command to run migrations and seeders:

      ./vendor/bin/sail artisan migrate
      ./vendor/bin/sail artisan db:seed
  6. JWT Setup

    • Generate JWT secret key:

      ./vendor/bin/sail artisan jwt:secret

Running the Application

  • With Laravel Sail, you can start your server by simply running:

    ./vendor/bin/sail up
  • To stop the server, you can use:

    ./vendor/bin/sail down
  • The API will be accessible at http://localhost. You can change the port in your docker-compose.yml file.

Usage

  • API routes are defined in routes/api.php.
  • Controllers are located in app/Http/Controllers/Api.
  • Requests can be made to http://localhost:8000/v1/api/.

Authentication

This boilerplate uses JWT for handling authentication. The following endpoints are available:

  • POST /v1/api/auth/login: to log in a user.
  • GET /v1/api/auth/me: to retrieve the authenticated user's profile.

Media & Image Handling

  • File uploads are handled through POST /api/media/upload.
  • Images can be manipulated using query parameters for resizing and formatting.

Testing

Run the PHPUnit tests with:

vendor/bin/phpunit

Contributing

Contributions, issues, and feature requests are welcome. Feel free to fork this repository and submit pull requests.

laravel-api-boilerplate's People

Contributors

bloopdex avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.