Back to Projects
02 / Solo Project

SmartCampus

A production-ready RESTful API built with JAX-RS (Jersey) for managing campus rooms and IoT sensors. Features full CRUD, sensor reading history, sub-resource locators, query filtering, HATEOAS discovery, and a global exception mapper — all running on an embedded Grizzly HTTP server.

JavaJAX-RSJerseyMavenREST APIGrizzly

Demo Video

Key Features

JAX-RS Sub-Resource Locators

Sensor readings are handled by a dedicated SensorReadingResource class, keeping each resource focused on a single responsibility.

Thread-Safe In-Memory Store

All data lives in a singleton DataStore backed by ConcurrentHashMap — safe under concurrent HTTP requests without manual synchronization.

Global Exception Mapper

Catches all unhandled exceptions and returns generic error responses, preventing stack traces and internal details from leaking to clients.

Request/Response Logging Filter

A JAX-RS ContainerRequestFilter logs every request and response automatically — no manual logging boilerplate in resource methods.

HATEOAS Discovery

The root endpoint returns navigable links to all resources so clients can explore the API without hardcoding URLs.

API Endpoints

GET/api/v1Discovery — lists all available resource links
GET/api/v1/roomsFetch all campus rooms
POST/api/v1/roomsCreate a new room
DELETE/api/v1/rooms/{roomId}Delete room — 409 if sensors attached
GET/api/v1/sensors?type=CO2Filter sensors by type via @QueryParam
POST/api/v1/sensors/{id}/readingsLog a sensor reading — 403 if MAINTENANCE

Base URL: http://localhost:8080/api/v1

Tech Stack

Java
🔗JAX-RS
⚙️Jersey
📦Maven
🌐REST API
{ }JSON

Project Structure

smart-campus-api/
├── pom.xml
└── src/main/java/com/smartcampus/
    ├── Main.java
    ├── SmartCampusApplication.java
    ├── model/
    │   ├── Room.java
    │   ├── Sensor.java
    │   └── SensorReading.java
    ├── store/
    │   └── DataStore.java
    ├── resource/
    │   ├── DiscoveryResource.java
    │   ├── RoomResource.java
    │   ├── SensorResource.java
    │   └── SensorReadingResource.java
    └── filter/
        └── LoggingFilter.java

How to Run

$git clone https://github.com/AshanWijesundara7/smart-campus-api.git
$cd smart-campus-api
$mvn clean package
$java -jar target/smart-campus-api-1.0-SNAPSHOT.jar

Server starts at http://localhost:8080/api/v1 · Requires Java 11+ and Maven 3.6+

All ProjectsNext Project →