Skip to content

Latest commit

 

History

History

sentiment-api

Sentiment API

Simple REST API for analyzing the sentiment of text.

Prerequisites

Before you can run this application, you will need to have the following installed:

  • Java 17 or later
  • Gradle 8.4 or later
  • Google Cloud Account

Getting Started

To get started, follow these steps:

  1. Clone the repository:

    git clone https://github.com/nais/examples.git
  2. Navigate to the project directory:

    cd sentiment-api
  3. Start the PostgreSQL database:

    docker-compose up db -d
  4. Build the application:

    ./gradlew build
  5. Run the application:

    ./gradlew bootRun

This will start the application on port 8080 on localhost.

Test the API using a tool like curl or httpie:

http localhost:8080/api/products

This should return an empty JSON array.

API Documentation

The API provides the following endpoints:

  • GET /api/products: Returns a list of all products.
  • GET /api/products/{id}: Returns the product with the specified ID.
  • POST /api/products: Creates a new product.
  • PUT /api/products/{id}: Updates the product with the specified ID.
  • DELETE /api/products/{id}: Deletes the product with the specified ID.
  • GET /api/products/{id}/reviews: Returns a list of all reviews for the product with the specified ID.
  • POST /api/products/{id}/reviews: Creates a new review for the product with the specified ID.

The request and response bodies are in JSON format. Here's an example of a product object:

{
    "name": "Lightsaber",
    "description": "An elegant weapon for a more civilized age.",
    "category": "OTHER",
    "price": 1000.00,
    "images": []
}

The species field can be one of the following values: TEE_SHIRT, HOODIE, CAP, OTHER.

License

This project is licensed under the MIT License. See the LICENSE file for details.