Skip to main content
This guide will walk you through setting up the Laravel Blog API and making your first authenticated API call.

Prerequisites

Before you begin, ensure you have the following installed:
  • PHP 7.1.3 or higher
  • Composer
  • MySQL or another supported database
  • Git

Setup steps

1

Clone the repository

Clone the Laravel Blog API repository to your local machine:
git clone <repository-url> laravel-blog-api
cd laravel-blog-api
2

Install dependencies

Install the required PHP packages using Composer:
composer install
This will install all dependencies including:
  • Laravel Framework 5.7
  • Firebase PHP-JWT 3.0.0
  • Laravel Tinker
3

Configure environment

Copy the example environment file and generate an application key:
cp .env.example .env
php artisan key:generate
Open the .env file and configure your database connection:
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
Make sure to create the database before running migrations.
4

Run database migrations

Create the necessary database tables:
php artisan migrate
This will create the users table and other required tables.
5

Start the development server

Launch the Laravel development server:
php artisan serve
The API will be available at http://localhost:8000.

Make your first API call

Now that your API is running, let’s make some authenticated requests.

Register a new user

Create your first user account by sending a POST request to the register endpoint:
curl -X POST http://localhost:8000/api/register \
  -H "Content-Type: application/json" \
  -d '{
    "json": "{\"name\":\"John\",\"surname\":\"Doe\",\"email\":\"[email protected]\",\"password\":\"secret123\"}"
  }'
The API expects user data to be sent as a JSON string within a json parameter. The password is hashed using SHA-256.

Login and get JWT token

Authenticate with your credentials to receive a JWT token:
curl -X POST http://localhost:8000/api/login \
  -H "Content-Type: application/json" \
  -d '{
    "json": "{\"email\":\"[email protected]\",\"password\":\"secret123\"}"
  }'
The response is a JWT token string. Save this token for making authenticated requests.
The JWT token expires after 7 days. You’ll need to login again to get a new token after expiration.

Make an authenticated request

Use the JWT token to make authenticated API calls. Here’s an example updating user information:
curl -X PUT http://localhost:8000/api/user/update \
  -H "Content-Type: application/json" \
  -H "Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." \
  -d '{
    "json": "{\"name\":\"Jane\",\"surname\":\"Doe\",\"email\":\"[email protected]\"}"
  }'
All authenticated endpoints require the JWT token in the Authorization header. Replace the token value with your actual token from the login response.

Next steps

Now that you’ve made your first authenticated API call, you can:
  • Explore the available endpoints in the API Reference
  • Learn about category and post management
  • Implement image upload functionality
  • Integrate the API into your application
The JWT token is validated using the secret key defined in app/Helpers/JwtAuth.php:13. In production, make sure to use a secure secret key.

Build docs developers (and LLMs) love