Products and users API of an agricultural coop

Mar 2025 - Apr 2025
API
APIJavaJakartaEEGlassfish

Presentation of the Anarchy Acres Cooperative Products and Users API (March - April 2025)

Context

As part of an R4.01 Software Architecture project, we each had to create a part of a website according to the following architecture:

Diagram of the architecture to implement

Diagram of the architecture to implement. Each DB is separated, and each API as well.

I was in charge of implementing the products and users API. The website concerned an agricultural cooperative wishing to sell its products directly via a platform available on the Internet.

The implemented API is in JakartaEE Glassfish. It relies on a strict layered architecture. The Resource Layer (JAX-RS) exposes REST endpoints and delegates processing to the Service Layer, which contains the business logic. Data is persisted via the Repository Layer (JDBC) which communicates with the MariaDB database, using entities defined in the Model Layer (Product, Type, Unit, User).

Implementation

Simple JSON Calls

The API allows managing the entire product catalog via standard JSON stream exchanges. Here are the main implemented functionalities:

DomainFunctionalitiesTechnical Details
ConsultationData readingRetrieval of product lists, product types, and units of measure, or retrieval by unique ID.
SearchDynamic filteringTextual search of products by their name via query parameter.
EditingCreation and ModificationAddition of new products/types (POST) and update of existing ones (PUT) with data validation.
DeletionCleanupDeletion of database entries via the DELETE method.
EnrichmentData MappingThe "Product" objects are automatically enriched with complete "Type" and "Unit" objects during serialization.

Remote Deployment

I deployed my API on a VPS in order to have complete flexibility regarding it. I used an Oracle VPS for this purpose, configuring it from A to Z.

For the needs of this online launch, security has been added and only GET calls are usable. Please be careful not to overuse my API!

Image Serving

Enabled by the remote deployment, image management does not go through the database (storage as BLOB) but through the server's file system to optimize performance.

  1. Reception: The ImageResource controller intercepts the GET request targeting a product ID.

  2. Metadata: The service first queries the database to validate the product's existence and retrieve its normalized name.

  3. Resolution: The system constructs the file path on the VPS disk (ex: /var/coop-images/ID_NAME.jpg).

  4. Fallback: If the specific file is not found, the service attempts to serve a generic default image before returning an error.

  5. Streaming: The binary file is returned with the appropriate MIME type (ex: image/jpeg).

Table of Possible Calls

Here is the exhaustive list of endpoints exposed by the API on the production server.

MethodComplete URLDescriptionExpected Return
GEThttps://79.72.25.28:8080/api/produitsLists all productsJSON Array (Products)
GEThttps://79.72.25.28:8080/api/produits/{id}Detail of a specific productJSON Object (Product)
GEThttps://79.72.25.28:8080/api/produits/search?nom={x}Search by nameJSON Array (Products)
GEThttps://79.72.25.28:8080/api/typesLists all types (categories)JSON Array (Types)
GEThttps://79.72.25.28:8080/api/types/{id}Detail of a typeJSON Object (Type)
GEThttps://79.72.25.28:8080/api/unitesLists all units of measureJSON Array (Units)
GEThttps://79.72.25.28:8080/api/images/produit/{id}Downloads the product imageBinary (Image/JPEG)
POSThttps://79.72.25.28:8080/api/produitsAdding a product (JSON Body)201 Created
PUThttps://79.72.25.28:8080/api/produits/{id}Modifying a product200 OK
DELETEhttps://79.72.25.28:8080/api/produits/{id}Deleting a product204 No Content
POSThttps://79.72.25.28:8080/api/images/produit/{id}Upload of an image (Binary)200 OK / 201 Created

Examples of GET Calls

Here is a list of direct URLs to test the read endpoints available on the production server:

Products

Types (Categories)

Measurement units

Images