Skip to content

youngyusuff6/blogger

Repository files navigation

Blog API

The Blog API is a Laravel-based RESTful API designed to manage blog posts and user authentication.

Features

  • User registration and login with JWT authentication.
  • Create, read, update, and delete blog posts.
  • Secure endpoints to ensure only authorized users can perform actions.
  • Token refresh functionality for extended sessions.

Getting Started

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/youngyusuff6/blogger.git
  2. Change into the project directory:

    cd blogger
  3. Install dependencies:

    composer install
  4. Copy the .env.example file to .env:

    cp .env.example .env
  5. Generate an application key:

    php artisan key:generate
  6. Configure your database in the .env file.

  7. Run migrations:

    php artisan migrate
  8. Start the development server:

    php artisan serve

Usage

  • Register a new user using the /register endpoint.
  • Log in to get a JWT token using the /login endpoint.
  • Use the token to access protected endpoints.
  • Manage blog posts using /blogs endpoints.

API Endpoints

User Authentication

  • POST /register

    • Register a new user.
    • Requires name, email, password, and confirm_password.
  • POST /login

    • Log in and obtain a JWT token.
    • Requires email and password.
  • POST /logout

    • Log out and invalidate the JWT token.
    • Requires a valid token in the Authorization header.
  • POST /refresh

    • Refresh a JWT token.
    • Requires a valid token in the Authorization header.

Blog Posts

  • GET /blogs

    • Get a list of all blog posts.
  • GET /my-blogs

    • Get a list of the user's blog posts.
    • Requires a valid token in the Authorization header.
  • POST /blogs

    • Create a new blog post.
    • Requires title and content.
    • Requires a valid token in the Authorization header.
  • PUT /blogs/{blog_id}

    • Update an existing blog post.
    • Requires title and content.
    • Requires a valid token in the Authorization header.
  • DELETE /blogs/{blog_id}

    • Delete an existing blog post.
    • Requires a valid token in the Authorization header.