Skip to content

BileMo API provides access to a catalog of high-end mobile phones.

Notifications You must be signed in to change notification settings

meline-p/bilemo

Repository files navigation

BileMo

Description

BileMo API provides access to a catalog of high-end mobile phones.

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/meline-p/bilemo.git
    cd bilemo
  2. Install dependencies with Composer:

    composer install
  3. Configure the environment by copying the .env file:

    cp .env .env.local

Configuration

  • APP_SECRET : Generate a random secret key

    php bin/console secrets:generate-keys
  • DATABASE_URL : Database connection URL.

  • JWT Token: Create a jwt folder in config directory. In your GitBash terminal, generate a private and public key: private key:

    openssl genpkey -out config/jwt/private.pem -aes256 -algorithm rsa -pkeyopt rsa_keygen_bits:4096

    public key:

    openssl pkey -in config/jwt/private.pem -out config/jwt/public.pem -pubout

    Change JWT_PASSPHRASE to your passphrase

Ensure these parameters are configured in the .env.local file.

Database

  1. Update the database:

    php bin/console doctrine:migrations:migrate
  2. (Optional) Load test data:

    php bin/console doctrine:fixtures:load

Usage

Launch the website

  • Start the local server:
    symfony serve

Cache

  • This API uses TagAwareCacheInterface for cache management. To clear or invalidate the cache by tag, you can use the following command:

    php bin/console cache:clear
  • Or to invalidate a specific tag:

    $cachePool->invalidateTags(['your_tag']);

Security

JWT tokens are employed to protect the API routes.

  • To generate a JWT token after authentication, send a POST request to:

    POST /api/login_check
  • Add the token to the Authorization header to access protected endpoints:

    Authorization: Bearer your_jwt_token

Documentation

The API is documented using NelmioApiDocBundle. After starting the server, the documentation is available at: http://localhost:8000/api/doc

Endpoints

Products

  • GET /api/products
  • GET /api/products/{id}

Users

  • GET /api/users
  • POST /api/users
  • GET /api/users/{id}
  • PUT /api/users/{id}
  • DELETE /api/users/{id}