##Overview
Simple RESTFul application with AngularJS client. Allows to store information about companies.
###Company
Represents entity Company
with attributes.
ATTRIBUTES
id
- unique ID generated by the server for the companyname
- full name of companyaddress
- address of company, should include street name and building numbercity
- company's location citycountry
- company's location countryemail
- company's contact emailphoneNumber
- company's contact phone numberbeneficials
- arrays of beneficials of current company, could be empty
###Beneficial
Represents entity Beneficial
with attributes.
ATTRIBUTES
id
- unique ID generated by the server for the beneficialcompanyId
- unique ID of beneficial's companyname
- full name of beneficial
#####Create a company
Request to create new company:
POST /companies
BODY ARGUMENTS
name
required
address
required
city
required
country
required
beneficials
required
email
optional
phoneNumber
optional
Creating of beneficial will be performed automatically in case beneficials
will be not empty. For a beneficial object, only one field are required name
.
Request Example
$ curl http://app-domain.com/rest/companies \
-H "Content-Type: application/json;charset=UTF-8" \
-d '{
"name": "company1",
"address": "Nikolskaya str., 14",
"city": "Moscow",
"country": "Russia",
"beneficials":[
{
"name": "Surname Name"
}
],
"email": "test@company1.com",
"phoneNumber": "+7 495 111 11 11"
}'
Response Example
HTTP/1.1 200 Created
Content-Type:application/json;charset=UTF-8
{
"id": 2453
"name": "company1",
"address": "Nikolskaya str., 14",
"city": "Moscow",
"country": "Russia",
"beneficials":[
{
"companyId": 2453,
"id":
"name": "Surname Name"
}
],
"email": "test@company1.com",
"phoneNumber": "+7 495 111 11 11"
}
Returned error codes
400
- in case company could not be created due to missed obligatory fields.
Error response example
HTTP/1.1 400 Bad Request
Content-Type:application/json;charset=UTF-8
{
"error":"Field 'Address' in company can not be empty"
}
#####Retrieve a company
Request to get details of an existing company:
GET /companies/{company_id}
URL ARGUMENTS
company_id
required
Request Example
$ curl http://app-domain.com/rest/companies/15 \
-H "Content-Type: application/json;charset=UTF-8" \
Response Example
HTTP/1.1 200 Created
Content-Type:application/json;charset=UTF-8
{
"id": "15",
"name": "company1",
"address": "Nikolskaya str., 14",
"city": "Moscow",
"country": "Russia",
"beneficials":[
{
"name": "Surname Name"
}
],
"email": "test@company1.com",
"phoneNumber": "+7 495 111 11 11"
}
Returned error codes
404
- in case company could not be found.
Error response example
HTTP/1.1 404 Not Found
Content-Type: text/plain
{
"error":"No company with id: 6591"
}
#####Retrieve all companies
Request to get details of all existing companies:
GET /companies
Request Example
$ curl http://app-domain.com/rest/companies \
-H "Content-Type: application/json;charset=UTF-8" \
Response Example
HTTP/1.1 200 OK
Content-Type:application/json;charset=UTF-8
[
{
"address":"Nikolskaya str., 14",
"beneficials":[
{
"companyId":6481,
"id":1541,
"name":"Surname Name"
}
],
"city":"Moscow",
"country":"Russia",
"email":"some@company1.com",
"id":6481,
"name":"company1",
"phoneNumber":"+7 495 111 11 11"
},
{
"address":"Lenina str., 1",
"beneficials":[
{
"companyId":6491,
"id":1551,
"name":"SomeOther Name"
}
],
"city":"Moscow",
"country":"Russia",
"email":"some@company2.com",
"id":6491,
"name":"company2",
"phoneNumber":"+7 495 222 22 22"
}
]
#####Update a company
Request to update details of an existing company:
PUT /companies/{company_id}
URL ARGUMENTS
company_id
required
BODY ARGUMENTS
name
required
address
required
city
required
country
required
beneficials
required
email
optional
phoneNumber
optional
Request Example
$ curl http://app-domain.com/rest/companies/15 \
-H "Content-Type: application/json;charset=UTF-8" \
-X PUT \
-d '{
"address":"Nikolskaya str., 14",
"beneficials":[
{
"companyId":6481,
"id":1541,
"name":"Surname Name"
}
],
"city":"Moscow",
"country":"Russia",
"email":"some@company1.com",
"id":6481,
"name":"New Company Name",
"phoneNumber":"+7 495 111 11 11"
}'
Response Example
HTTP/1.1 200 OK
Content-Type:application/json;charset=UTF-8
{
"address":"Nikolskaya str., 14",
"beneficials":[
{
"companyId":6481,
"id":1541,
"name":"Surname Name"
}
],
"city":"Moscow",
"country":"Russia",
"email":"some@company1.com",
"id":6481,
"name":"New Company Name",
"phoneNumber":"+7 495 111 11 11"
}
Returned error codes
404
- in case company could not be found
400
- in case some fields are not filled
Error response example
HTTP/1.1 404 Not Found
Content-Type: text/plain
{
"error":"No company with id: 6481"
}
#####Add a beneficial
Request to create new company:
POST /companies/{company_id}/beneficials
URL ARGUMENTS
company_id
required
BODY ARGUMENTS
name
required
Request Example
$ curl http://app-domain.com/rest/companies/6481/beneficials \
-H "Content-Type: application/json;charset=UTF-8" \
-d '{
"name":"Jack Sparrow"
}'
Response Example
HTTP/1.1 200 OK
Content-Type:text/plain;charset=UTF-8
Returned error codes
404
- in case company could not be found
400
- in case some fields are not filled
Error response example
HTTP/1.1 404 Not Found
Content-Type: text/plain
{
"error":"No company with id: 6481"
}