A RESTful API built with JAX-RS (Jersey) and Apache Tomcat for managing rooms and sensors across a university smart campus infrastructure. Developed as coursework for 5COSC022W Client-Server Architectures at the University of Westminster.
- Java 8
- JAX-RS 2.1 (Jersey 2.32)
- Apache Tomcat 9
- Maven
- Jackson (JSON serialisation)
- Apache NetBeans IDE
The API follows REST principles with a versioned base path of /api/v1.
All responses are in JSON format. The resource hierarchy reflects the
physical structure of the campus:
- A Room is a physical space that contains sensors
- A Sensor belongs to exactly one room and records measurements
- A SensorReading is a historical record of a sensor measurement
The API uses a Singleton in-memory DataStore using HashMaps to store all data. No database is used.
GET /api/v1/ Discovery endpoint GET /api/v1/rooms List all rooms POST /api/v1/rooms Create a room GET /api/v1/rooms/{roomId} Get a specific room DEL /api/v1/rooms/{roomId} Delete a room GET /api/v1/sensors List all sensors GET /api/v1/sensors?type={type} Filter sensors by type POST /api/v1/sensors Register a sensor GET /api/v1/sensors/{sensorId} Get a specific sensor DEL /api/v1/sensors/{sensorId} Delete a sensor GET /api/v1/sensors/{sensorId}/readings Get reading history POST /api/v1/sensors/{sensorId}/readings Add a new reading
- Java JDK 8 or higher installed
- Apache NetBeans IDE installed
- Apache Tomcat 9 configured in NetBeans Services tab
- Maven (bundled with NetBeans)
-
Clone this repository: git clone https://github.com/YOUR_USERNAME/smart-campus-api.git
-
Open NetBeans and go to File → Open Project
-
Navigate to the cloned folder and select it, then click Open Project
-
Right-click the project in the Projects panel and select Clean and Build. Wait for Maven to download dependencies and build successfully.
-
Right-click the project again and select Run. Tomcat will start and deploy the application automatically.
-
The API is now available at: http://localhost:8080/smart-campus-api/api/v1/
curl -X GET http://localhost:8080/smart-campus-api/api/v1/
curl -X POST http://localhost:8080/smart-campus-api/api/v1/rooms -H "Content-Type: application/json" -d "{"id":"LIB-301","name":"Library Quiet Study","capacity":50}"
curl -X POST http://localhost:8080/smart-campus-api/api/v1/sensors -H "Content-Type: application/json" -d "{"id":"TEMP-001","type":"Temperature","status":"ACTIVE","currentValue":0.0,"roomId":"LIB-301"}"
curl -X GET "http://localhost:8080/smart-campus-api/api/v1/sensors?type=Temperature"
curl -X POST http://localhost:8080/smart-campus-api/api/v1/sensors/TEMP-001/readings -H "Content-Type: application/json" -d "{"value":23.5}"
curl -X DELETE http://localhost:8080/smart-campus-api/api/v1/rooms/LIB-301
curl -X POST http://localhost:8080/smart-campus-api/api/v1/sensors -H "Content-Type: application/json" -d "{"id":"CO2-999","type":"CO2","status":"ACTIVE","currentValue":0.0,"roomId":"FAKE-ROOM"}"
Student Name: Samitha Bandara
Student ID: w2119852 (20240161)
Module: 5COSC022W Client-Server Architectures
University of Westminster