Restful Webservice to allow the users to perform CRUD operations to create, view, update and delete stations.
- Requirements
- Setup
- Deployment
- API Endpoints
-
Java 8
-
Gradle
-
Clone the repository.
-
Execute
cd spring-jpa-gradle
There are two ways to deploy the web application.
As this is a Maven project, it can be imported in an IDE such as Eclipse or IntelliJ as a Maven Project. Create a Run configuration -> Java Application. Once done, select App as a main-class. The application will be deployed to an embedded TOMCAT container
Build and compile the project from command line. Navigate to the project root using the command line, and execute the following command gradle bootRun
. You will need maven plugin for that.
The RESTful services can be invoked after either steps is performed.
IMPORTANT: these two instructions are mutually exclusive.
POST /iheartmedia/station
Creates a station.
Name | Type | Description | Required |
---|---|---|---|
stationId | string | Unique station id | true |
stationName | string | Station name | true |
callSign | string | Unique call sign | true |
hdEnabled | string | HD Enabled | false |
The sample request is given below:
{
"stationId": "KISS-FM",
"hdEnabled": false,
"callSign": "KISS",
"name": "102.7 KIIS-FM-Los Angeles",
"createdAt": <UTC Timestamp when the station was created.>
}
A response status code will be 201 Created and will have the following characteristics.
Name | Type | Description | Required |
---|---|---|---|
stationId | string | Unique station id | true |
stationName | string | Station name | true |
callSign | string | Unique call sign | true |
hdEnabled | string | Indicator as whether the statino is HD enabled | true |
createdAt | timestamp | UTC Timestamp |
The error response body represents an error of errors returned as 200 OK
Name | Type | Description | Read only |
---|---|---|---|
errors | array | array of error objects | true |
where each error object consists of the following fields
Name | Type | Description | Read only |
---|---|---|---|
error code | number | error code indicating the kind of error | true |
error message | string | user friendly message | true |
Some of the sample responses are given below
{
"errors": [
{
"code": 409,
"message": "Station information can not be persisted. Check if the station information already exists."
}
]
}
PUT /iheartmedia/station/<stationId>
Updates the station information. Station ID is considered to be unique, and can not be updated, once updated.
The request body can only consist of maximum of three fields given. A missing field is ignored by the system. Station ID can not be updated. Some of the expected fields are given below.
Name | Type | Description | Required |
---|---|---|---|
stationName | string | Station name | false |
callSign | string | Unique call sign | false |
hdEnabled | string | HD Enabled | false |
The request body is given below
{
"hdEnabled": false,
"callSign": "KISS",
"name": "102.7 KIIS-FM-Los Angeles"
}
The response will return a 200 OK status. The response body will have the following attributes.
Name | Type | Description | Required |
---|---|---|---|
stationId | string | Unique station id | true |
stationName | string | Station name | true |
callSign | string | Unique call sign | true |
hdEnabled | string | Indicator as whether the station is HD enabled | true |
updatedAt | timestamp | UTC Timestamp | true |
A sample response body is given below.
{
"stationId": "KISS-FM",
"hdEnabled": true,
"callSign": "New2",
"name": "Updated Station name",
"updatedAt": "2018-12-09T11:54:52.407"
}
The error response encapsulates an array of errors.
Name | Type | Description | Read only |
---|---|---|---|
errors | array | array of error objects | true |
where each error object consists of the following data sets.
Name | Type | Description | Read only |
---|---|---|---|
error code | number | error code indicating the kind of error | true |
error message | string | user friendly message | true |
Some of the sample responses are given below
This will return a 404 error if no record for the quiz was found in the database.
{
"errors": [
{
"code": 404,
"message": "Station was not found for station id: KISS-FM-1."
}
]
}
{
"errors": [
{
"code": 400,
"message": "Call sign New23 is of invalid length. Station call sign must be 4 characters long."
}
]
}
DELETE /iheartmedia/station/<stationId>
Deletes the station by station id and returns the deleted station entity.
The response will return a 200 OK status. The response body will have the following attributes.
Name | Type | Description | Required |
---|---|---|---|
stationId | string | Unique station id | true |
stationName | string | Station name | true |
callSign | string | Unique call sign | true |
hdEnabled | string | Indicator as whether the station is HD enabled | true |
deletedAt | timestamp | UTC Timestamp | true |
The sample response is given below:
{
"stationId": "KISS-FM",
"hdEnabled": true,
"callSign": "New2",
"name": "Updated Station name",
"deletedAt": "2018-12-09T12:03:03.59"
}
The error response encapsulates an array of errors.
Name | Type | Description | Read only |
---|---|---|---|
errors | array | array of error objects | true |
where each error object consists of the following data sets.
Name | Type | Description | Read only |
---|---|---|---|
error code | number | error code indicating the kind of error | true |
error message | string | user friendly message | true |
Some of the sample responses are given below
{
"errors": [
{
"code": 404,
"message": "Station was not found for station id: KISS-FM."
}
]
}
GET /iheartmedia/stations
Returns all stations
The response will return a 200 OK status. The response body will comprise an array of station objects, each of which will encapsulate the following attributes.
Name | Type | Description | Required |
---|---|---|---|
stationId | string | Unique station id | true |
stationName | string | Station name | true |
callSign | string | Unique call sign | true |
hdEnabled | string | Indicator as whether the station is HD enabled | true |
The sample response is given below
[
{
"stationId": "KISS-FM",
"hdEnabled": true,
"callSign": "WISS",
"name": "102.7 KIIS-FM-Los Angeles"
}
]
GET /iheartmedia/station/id/<stationId>
Returns unique station by station id
The response will return a 200 OK status. The response body comprise of the following attributes
Name | Type | Description | Required |
---|---|---|---|
stationId | string | Unique station id | true |
stationName | string | Station name | true |
callSign | string | Unique call sign | true |
hdEnabled | string | Indicator as whether the station is HD enabled | true |
The sample response is given below
{
"stationId": "KISS-FM",
"hdEnabled": true,
"callSign": "WISS",
"name": "102.7 KIIS-FM-Los Angeles"
}
The error response encapsulates an array of errors.
Name | Type | Description | Read only |
---|---|---|---|
errors | array | array of error objects | true |
where each error object consists of the following data sets.
Name | Type | Description | Read only |
---|---|---|---|
error code | number | error code indicating the kind of error | true |
error message | string | user friendly message | true |
Some of the sample responses are given below
{
"errors": [
{
"code": 404,
"message": "Station was not found for station id: KISS-FM."
}
]
}
GET /iheartmedia/station/name/<stationId>
Returns unique station by station name
The response will return a 200 OK status. The response body will comprise of the following attributes
Name | Type | Description | Required |
---|---|---|---|
stationId | string | Unique station id | true |
stationName | string | Station name | true |
callSign | string | Unique call sign | true |
hdEnabled | string | Indicator as whether the station is HD enabled | true |
The sample response is given below
{
"stationId": "KISS-FM",
"hdEnabled": true,
"callSign": "WISS",
"name": "102.7 KIIS-FM-Los Angeles"
}
The error response encapsulates an array of errors.
Name | Type | Description | Read only |
---|---|---|---|
errors | array | array of error objects | true |
where each error object consists of the following data sets.
Name | Type | Description | Read only |
---|---|---|---|
error code | number | error code indicating the kind of error | true |
error message | string | user friendly message | true |
Some of the sample responses are given below
{
"errors": [
{
"code": 404,
"message": "Station was not found for station name: 102.7 KIIS-FM-Los Angeles-2."
}
]
}
GET /swagger-ui.html
GET /actuator/health
GET /actuator/info