SONIC API Logo

SONIC API Manual

Welcome to the SONIC API manual page

Welcome to SONIC API, a simple and efficient API service that returns an album cover image for a given artist. This service normalizes the artist's name, removes unnecessary words like "the", and fetches the album cover based on a predefined mapping of artist names to cover images.

Overview

How It Works

  1. The API normalizes the artist name to avoid variations (e.g., capitalization, special characters).
  2. It searches for the artist in a JSON-based artist-cover mapping file (`/public/artist-covers.json`).
  3. If the artist is found, it returns the corresponding `.webp` image from the `/public/covers` folder.
  4. If not found, it returns a default "not-found.webp" image.

Getting Started

Installation

  1. Clone the repository:
  2. git clone https://github.com/ncradio-fm/sonic-api
  3. Set up your environment variables. Create a .env.local file using the provided env-example:
  4. cp env-example .env.local
  5. Update .env.local with your configuration:
  6. API_KEY=your-api-key-here

Running the Application

To start the development server, run:

npm run dev

This will run the server in development mode. The API will be available at http://localhost:3000.

API Request

Endpoint:

GET /api/album-cover?artist=<artist-name>

Headers

Example Requests

Request:

GET http://localhost:3000/api/album-cover?artist=The%20Beatles

Response:

Error Handling

Environment Variables

API Usage Example (Production)

To call the API in production, you need to include the x-api-key header with your request. Below is an example using curl:

curl -H "x-api-key: your-api-key-here" "https://your-production-url/api/album-cover?artist=The%20Beatles"

This will send a GET request to the API to fetch the album cover for the artist The Beatles, with the API key provided in the headers.

Ensure that you replace your-api-key-here with the actual API key and your-production-url with the correct production URL of your API.

Author

Made by NikitaY.
(C) 01-Sep-2024, nikitay.com