Company REST Assessment
- Author: Luciano Greiner
Returns a json array containing of summarized company data objects.
-
URL: /rest/companies
-
Method:
GET
-
URL Params: None
-
Data Params: None
-
Success Response:
- Code: 200
- Description: OK
- Content:
[{ "id" : 1, "name" : "Google", "email" : "[email protected]", "address" : { "city" : "Palo Alto", "country" : "USA" } }, ... ]
- Code: 200
-
Sample Call:
$ curl -i -X GET https://company-crud.herokuapp.com/rest/companies
Returns a json object containing a company record information.
-
URL: /rest/companies/:id
-
Method:
GET
-
URL Params:
Required:
id=[integer]
-
Data Params: None
-
Success Response:
- Code: 200
-
Description: OK
-
Content:
{ "id" : 1, "name" : "Google", "email" : "[email protected]", "phone" : "123 123-45678", "address" : { "street" : "Google Street", "city" : "Palo Alto", "country" : "USA" }, "owners" : ["Larry Page", ...] }
-
- Code: 200
-
Error Responses:
- Code: 404
- Description: NOT FOUND
- Detail: Returned in case the given company id is not found
- Code: 404
-
Sample Call:
$ curl -i -X GET https://company-crud.herokuapp.com/rest/companies/1
Insert a given a json object containing a company record into the database.
-
URL: /rest/companies
-
Method:
POST
-
URL Params: None
-
Data Params:
- Content-Type: application/json
- Sample Data:
{ "name" : "Acme Inc", "email" : "[email protected]", "phone" : "123 123-45678", "address" : { "street" : "Acme Street", "city" : "Orlando", "country" : "USA" }, "owners" : ["John Smith", ...] }
-
Success Response:
- Code: 201
- Description: CREATED
- Headers:
- Location: /companies/20 (Inserted company location)
- Code: 201
-
Error Responses:
- Code: 400
- Description: BAD REQUEST
- Detail: Returned in case the given company object is not valid
- Code: 400
-
Sample Call:
$ curl -H "Content-Type: application/json" -X POST -d '{"name":"Acme Inc","email":"[email protected]","phone":"123 123-45678","address":{"street":"Acme Street","city":"Orlando","country":"USA"},"owners":["John Smith"]}' https://company-crud.herokuapp.com/rest/companies
Update the record of a given company ID
-
URL: /rest/companies/:id
-
Method:
PUT
-
URL Params:
Required:
id=[integer]
-
Data Params:
- Content-Type: application/json
- Sample Data:
{ "name" : "Acme Inc", "email" : "[email protected]", "phone" : "123 123-45678", "address" : { "street" : "Acme Street", "city" : "Orlando", "country" : "USA" }, "owners" : ["Josh Town", ...] }
-
Success Response:
- Code: 202
- Description: ACCEPTED
- Detail: Returned in case the given company was successfuly updated
- Code: 202
-
Error Responses:
-
Code: 404
- Description: NOT FOUND
- Detail: Returned in case the given company id is not found
-
Code: 400
- Description: BAD REQUEST
- Detail: Returned in case the given company object is not valid
-
-
Sample Call:
$ curl -H "Content-Type: application/json" -X PUT -d '{"name":"Acme Inc","email":"[email protected]","phone":"123 123-45678","address":{"street":"Acme Street","city":"Orlando","country":"USA"},"owners":["Josh Town"]}' https://company-crud.herokuapp.com/rest/companies/20
Add a named owner to a company record of the given ID
-
URL: /rest/companies/:id/owner
-
Method:
PUT
-
URL Params:
Required:
id=[integer]
-
Data Params:
- Content-Type: application/x-www-form-urlencoded
- Required:
name=[string]
-
Success Response:
- Code: 202
- Description: ACCEPTED
- Detail: Returned in case the given company owner was successfuly added
-
Error Responses:
- Code: 404
- Description: NOT FOUND
- Detail: Returned in case the given company id is not found
- Code: 404
-
Sample Call:
$ curl -H "Content-Type: application/x-www-form-urlencoded" -X PUT -d 'name=Marie+Cruz' https://company-crud.herokuapp.com/rest/companies/20/owner