Skip to content

REST API that supports all CRUD operations for trucks and loads

Notifications You must be signed in to change notification settings

jasminjohal/trucking-company-api

Repository files navigation

Trucking Company API

About

This is an expanded version of the final project I built for the CS 493 (Cloud Application Development) course at OSU. It is a REST API that supports all CRUD operations for trucks and loads. The data model and the request and response parameters for all endpoints are outlined below. The API is hosted on Google App Engine and the base URL is https://portfolio-johalj.uw.r.appspot.com/.

add truck postman endpoint

Sample response for POST /trucks endpoint

Authorization

Some endpoints are protected and require an access token. To acquire this token, login/signup here. You will be redirected to a page that contains a JSON object. The id_token property contains the access token.

Table of Contents

  1. Data Model
  2. View All Users
  3. Create a Truck
  4. View a Truck
  5. View All Trucks
  6. Edit a Truck (Put)
  7. Edit a Truck (Patch)
  8. Delete a Truck
  9. Delete All Trucks
  10. Create a Load
  11. View a Load
  12. View All Loads
  13. Edit a Load (Put)
  14. Edit a Load (Patch)
  15. Delete a Load
  16. Delete All Loads
  17. Managing Loads: Load Assigned to Truck
  18. Managing Loads: Load Removed from Truck

Data Model

The app stores three kinds of entities in Datastore: Users, Trucks, and Loads. Users and Trucks are related since each Truck has an owner property which corresponds to the sub property of a User. Users and Trucks have a one-to-many relationship. A single User can own many Trucks, but a Truck can only have one owner. Trucks and Loads are also related via a one-to-many relationship. A Truck can contain many Loads while a Load can only be on a single Truck.

Users

Property Data Type Notes Example
id Integer The unique ID of the user (automatically generated by Datastore).
name String The username of the user. "[email protected]"
sub String The complete subject claim of the user's JWT. "auth0|629b81bdcd1f83006faceb4d"

Note: both the id and sub properties are unique identifiers, but the id property is irrelevant to this application. The sub property is used to identify users and it links the Users kind to the Trucks kind.

Trucks

Property Data Type Notes Example Required? Valid Request Parameters
id Integer The unique ID of the truck. Datastore automatically generates it. N/A No N/A
owner String The sub of the user that owns the truck. "auth0|629b81bdcd1f83006faceb4d" No N/A
truck_vin String The vehicle identification number of the truck. "1FUJBGAN04HM86987" Yes 17-character string (only alphanumeric characters)
trailer_vin String The vehicle identification number of trailer. "1B3ES56C55D137449" Yes 17-character string (only alphanumeric characters)
truck_model String The model of the truck. "Kenworth T680" Yes Maximum 50 characters (alphanumeric & spaces only)
trailer_type String The type of the trailer. "Flatbed" Yes Maximum 20 characters (alphanumeric & spaces only)
trailer_capacity Integer The maximum weight (lbs) a trailer can hold. 45000 Yes An integer between 1 and 100,000
loads Array A list of the loads on the truck. ["123", "456", "789"] No N/A

Loads

Property Data Type Notes Example Required? Valid Request Parameters
id Integer The unique ID of the load. Datastore automatically generates it. No N/A
carrier String or Null If the load is on a truck, then carrier is the id of the truck. Otherwise, it is null. "5665248644169728" No N/A
vendor String The supplier of the item. "Driscoll's" Yes Maximum 50 characters (letters, apostrophes, and spaces only)
item String The items in the load. "Organic strawberries" Yes Maximum 50 characters (letters and spaces only)
quantity Integer The number of cases of the item. 240 Yes An integer between 1 and 100,000
weight Floating point number The weight (lbs) of the load. 465.75 Yes A number between 1 and 100,000

View All Users

List all the users.

GET /users

Protected?

No.

Request

Path Parameters

None

Request Body

None

Response

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Success 200 OK The response contains a property data which is a list of all the users in the database.
Failure 406 Not Acceptable The client wants a media type other than JSON.

Response Examples

Success

Status: 200 OK

{
  "data": [
    {
      "sub": "auth0|629b9c27337c6c00708f13d5",
      "name": "[email protected]",
      "id": "5995848483733504"
    },
    {
      "sub": "auth0|629bec02cd1f83006facf42b",
      "name": "[email protected]",
      "id": "6246730945265664"
    },
    {
      "name": "[email protected]",
      "sub": "auth0|629b81bdcd1f83006faceb4d",
      "id": "6264616665481216"
    }
  ]
}

Failure

Status: 406 Not Acceptable

{
  "Error": "This application only supports JSON responses"
}

Create a Truck

Allows you to create a new truck.

POST /trucks

Protected?

Yes. The request must be accompanied by a valid bearer token.

Request

Path Parameters

None

Request Body

Required

Request Body Format

application/json

Request JSON Attributes

Name Description Required?
truck_vin The vehicle identification number of the truck. Yes
trailer_vin The vehicle identification number of the trailer. Yes
truck_model The model of the truck (E.g. "Kenworth T680"). Yes
trailer_type The model of the trailer (E.g. "Flatbed"). Yes
trailer_capacity The maximum weight (lbs) a trailer can hold (E.g. 45000). Yes

Request Body Example

{
  "truck_vin": "1FUJBGAN04HM86987",
  "trailer_vin": "1B3ES56C55D137449",
  "truck_model": "Kenworth T680",
  "trailer_type": "Refrigerated",
  "trailer_capacity": 45000
}

Response

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Success 201 Created Extraneous attributes will be ignored.
Failure 400 Bad Request The request is missing any of the required attributes.
Failure 401 Unauthorized The bearer token is missing or invalid.
Failure 415 Unsupported Media Type The request is not JSON.

Response Examples

Success

Status 201 Created

{
  "trailer_capacity": 45000,
  "trailer_vin": "1B3ES56C55D137449",
  "loads": [],
  "trailer_type": "Refrigerated",
  "truck_vin": "1FUJBGAN04HM86987",
  "owner": "auth0|629b81bdcd1f83006faceb4d",
  "truck_model": "Kenworth T680",
  "id": "5284414665785344",
  "self": "http://127.0.0.1:8080/trucks/5284414665785344"
}

Failure

Status: 400 Bad Request

{
  "Error": "The request object is missing at least one of the required attributes"
}

Status: 401 Unauthorized Error

{
  "Error": "Invalid token."
}

Status: 415 Unsupported Media Type

{
  "Error": "Server only accepts application/json data."
}

View a Truck

Allows you to get an existing truck

GET /truck/:truck_id

Protected?

Yes. The request must be accompanied by a valid bearer token.

Request

Path Parameters

Name Description
truck_id ID of the truck

Request Body

None

Response

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Success 200 OK
Failure 401 Unauthorized The bearer token is missing or invalid.
Failure 403 Forbidden The bearer token is valid but does not correspond to the correct owner of the truck.
Failure 404 Not Found No truck with this truck_id exists
Failure 406 Not Acceptable The client wants a media type other than JSON.

Response Examples

Success

Status: 200 OK

{
  "truck_vin": "1FUJBGAN04HM86987",
  "loads": [
    {
      "id": "6523730297618432",
      "self": "http://127.0.0.1:8080/loads/6523730297618432"
    }
  ],
  "trailer_capacity": 45000,
  "trailer_vin": "1B3ES56C55D137449",
  "truck_model": "Kenworth T680",
  "trailer_type": "Refrigerated",
  "owner": "auth0|629b81bdcd1f83006faceb4d",
  "id": "5284414665785344",
  "self": "http://127.0.0.1:8080/trucks/5284414665785344"
}

Failure

Status: 401 Unauthorized

{
  "Error": "Invalid token."
}

Status: 403 Forbidden

{
  "Error": "You do not have access to this truck"
}

Status: 404 Not Found

{
  "Error": "No truck with this truck_id exists"
}

Status: 406 Not Acceptable

{
  "Error": "This application only supports JSON responses"
}

View All Trucks

List all the trucks owned by a particular owner.

GET /trucks

Protected?

Yes. The request must be accompanied by a valid bearer token.

Request

Path Parameters

None

Request Body

None

Response

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Success 200 OK The response contains a property data which is a list of all the trucks owned by the specified owner.
Failure 401 Unauthorized The bearer token is missing or invalid.
Failure 406 Not Acceptable The client wants a media type other than JSON.

Response Examples

Success

Status: 200 OK

{
  "data": [
    {
      "trailer_type": "Refrigerated",
      "truck_model": "Freightliner M2 106",
      "owner": "auth0|629b81bdcd1f83006faceb4d",
      "loads": [],
      "truck_vin": "JH4KA4576KC031014",
      "trailer_vin": "JH4DA3350HS000229",
      "trailer_capacity": 40000,
      "id": "4824921112838144",
      "self": "http://127.0.0.1:8080/trucks/4824921112838144"
    },
    {
      "trailer_vin": "1B3ES56C55D137449",
      "trailer_capacity": 45000,
      "truck_model": "Kenworth T680",
      "owner": "auth0|629b81bdcd1f83006faceb4d",
      "loads": [
        {
          "id": "6136585972088832",
          "self": "http://127.0.0.1:8080/loads/6136585972088832"
        }
      ],
      "truck_vin": "1FUJBGAN04HM86987",
      "trailer_type": "Refrigerated",
      "id": "5010686065246208",
      "self": "http://127.0.0.1:8080/trucks/5010686065246208"
    },
    {
      "truck_vin": "1C3BF66P0GX570598",
      "truck_model": "Peterbilt 389",
      "loads": [],
      "trailer_vin": "LM4AC113061105688",
      "trailer_type": "Refrigerated",
      "trailer_capacity": 45000,
      "owner": "auth0|629b81bdcd1f83006faceb4d",
      "id": "5566276323770368",
      "self": "http://127.0.0.1:8080/trucks/5566276323770368"
    },
    {
      "owner": "auth0|629b81bdcd1f83006faceb4d",
      "truck_model": "Kenworth T800",
      "trailer_type": "Flatbed",
      "truck_vin": "1FABP21B4CK165368",
      "trailer_capacity": 45000,
      "trailer_vin": "3N1BC13E99L480541",
      "loads": [],
      "id": "6101517832552448",
      "self": "http://127.0.0.1:8080/trucks/6101517832552448"
    },
    {
      "owner": "auth0|629b81bdcd1f83006faceb4d",
      "loads": [],
      "truck_model": "Freightliner Cascadia",
      "trailer_type": "Dry Van",
      "trailer_capacity": 20000,
      "trailer_vin": "1G4HP54KX24151104",
      "truck_vin": "JTJZB1BA8A2400307",
      "id": "6129226277191680",
      "self": "http://127.0.0.1:8080/trucks/6129226277191680"
    },
    {
      "truck_vin": "1GCCS1442W8181753",
      "trailer_capacity": 30000,
      "loads": [
        {
          "id": "6732143317221376",
          "self": "http://127.0.0.1:8080/loads/6732143317221376"
        },
        {
          "id": "6128839595917312",
          "self": "http://127.0.0.1:8080/loads/6128839595917312"
        }
      ],
      "trailer_vin": "JH4DA9340PS000417",
      "owner": "auth0|629b81bdcd1f83006faceb4d",
      "trailer_type": "Flatbed",
      "truck_model": "Mack Anthem",
      "id": "6232295996391424",
      "self": "http://127.0.0.1:8080/trucks/6232295996391424"
    }
  ]
}

Failure

Status: 401 Unauthorized

{
  "Error": "Invalid token."
}

Status: 406 Not Acceptable

{
  "Error": "This application only supports JSON responses"
}

Edit a Truck (Put)

Allows you to overwrite all attributes of a truck, except owner and loads.

Side effect : loads will be reset to an empty array and any load entity that was previously on the truck will no longer have a carrier.

PUT /trucks/:truck_id

Protected?

Yes. The request must be accompanied by a valid bearer token.

Request

Path Parameters

Name Description
truck_id ID of the truck

Request Body

Required

Request Body Format

application/json

Request JSON Attributes

Name Description Required?
truck_vin The vehicle identification number of the truck. Yes
trailer_vin The vehicle identification number of the trailer. Yes
truck_model The model of the truck (E.g. "Kenworth T680"). Yes
trailer_type The model of the trailer (E.g. "Flatbed"). Yes
trailer_capacity The maximum weight (lbs) a trailer can hold (E.g. 45000). Yes

Request Body Example

{
  "truck_vin": "1GCCS1442W8181753",
  "trailer_vin": "JH4DA9340PS000417",
  "truck_model": "Mack Anthem",
  "trailer_type": "Dry Van",
  "trailer_capacity": 28000
}

Response

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Success 200 OK The input can contain extraneous attributes. Any attributes aside from the required attributes listed above will be ignored.
Failure 400 Bad Request The request is missing any of the required attributes.
Failure 401 Unauthorized The bearer token is missing or invalid.
Failure 403 Forbidden The bearer token is valid but does not correspond to the correct owner of the truck.
Failure 404 Not Found No truck with this truck_id exists.
Failure 406 Not Acceptable The client wants a media type other than JSON.
Failure 415 Unsupported Media Type The request is not JSON.

Response Examples

Success

Status: 200 OK

{
  "trailer_type": "Dry Van",
  "truck_vin": "1GCCS1442W8181753",
  "truck_model": "Mack Anthem",
  "loads": [],
  "owner": "auth0|629b81bdcd1f83006faceb4d",
  "trailer_vin": "JH4DA9340PS000417",
  "trailer_capacity": 28000,
  "id": "6124252570845184",
  "self": "http://127.0.0.1:8080/trucks/6124252570845184"
}

Failure

Status: 400 Bad Request

{
  "Error": "The request object is missing at least one of the required attributes"
}

Status: 401 Unauthorized

{
  "Error": "Invalid token."
}

Status: 403 Forbidden

{
  "Error": "You do not have access to this truck"
}

Status: 404 Not Found

{
  "Error": "No truck with this truck_id exists"
}

Status: 406 Not Acceptable

{
  "Error": "This application only supports JSON responses"
}

Status: 415 Unsupported Media Type

{
  "Error": "Server only accepts application/json data."
}

Edit a Truck (Patch)

Allows you to overwrite any subset of attributes of a truck, excluding loads and owner. The attributes that weren't explicitly overwritten in the request will remain unchanged.

Note: the relationship between a truck and its loads will remain unchanged.

PATCH /trucks/:truck_id

Protected?

Yes. The request must be accompanied by a valid bearer token.

Request

Path Parameters

Name Description
truck_id ID of the truck

Request Body

Required

Request Body Format

application/json

Request JSON Attributes

Name Description Required?
truck_vin The vehicle identification number of the truck. No
trailer_vin The vehicle identification number of the trailer. No
truck_model The model of the truck (E.g. "Kenworth T680"). No
trailer_type The model of the trailer (E.g. "Flatbed"). No
trailer_capacity The maximum weight (lbs) a trailer can hold (E.g. 45000). No

Request Body Example

{
  "truck_vin": "1GTEC14W1YZ246726",
  "trailer_vin": "1J4RR5GT2BC512008"
}

Response

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Success 200 OK The input can contain extraneous attributes. Any attributes aside from the required attributes listed above will be ignored.
Failure 400 Bad Request The request doesn't contain at least one of the required attributes.
Failure 401 Unauthorized The bearer token is missing or invalid.
Failure 403 Forbidden The bearer token is valid but does not correspond to the correct owner of the truck.
Failure 404 Not Found No truck with this truck_id exists.
Failure 406 Not Acceptable The client wants a media type other than JSON.
Failure 415 Unsupported Media Type The request is not JSON.

Response Examples

Success

Status: 200 OK

{
  "trailer_type": "Refrigerated",
  "owner": "auth0|629b81bdcd1f83006faceb4d",
  "loads": [
    {
      "id": "5563792926703616",
      "self": "http://127.0.0.1:8080/loads/5563792926703616"
    },
    {
      "id": "6689692833546240",
      "self": "http://127.0.0.1:8080/loads/6689692833546240"
    }
  ],
  "truck_model": "Kenworth T680",
  "trailer_vin": "1J4RR5GT2BC512008",
  "trailer_capacity": 45000,
  "truck_vin": "1GTEC14W1YZ246726",
  "id": "4971907073966080",
  "self": "http://127.0.0.1:8080/trucks/4971907073966080"
}

Failure

Status: 400 Bad Request

{
  "Error": "The request object is missing at least one of the required attributes"
}

Status: 401 Unauthorized

{
  "Error": "Invalid token."
}

Status: 403 Forbidden

{
  "Error": "You do not have access to this truck"
}

Status: 404 Not Found

{
  "Error": "No truck with this truck_id exists"
}

Status: 406 Not Acceptable

{
  "Error": "This application only supports JSON responses"
}

Status: 415 Unsupported Media Type

{
  "Error": "Server only accepts application/json data."
}

Delete a Truck

Allows you to delete a truck.

Side effect : If the truck contains a load, the deletion of the truck will update the load entity so that it no longer belongs to a truck.

DELETE /trucks/:truck_id

Protected?

Yes. The request must be accompanied by a valid bearer token.

Request

Path Parameters

Name Description
truck_id ID of the truck

Request Body

None

Response

No body

Response Body Format

Success: No body

Failure: application/json

Response Statuses

Outcome Status Code Notes
Success 204 No Content
Failure 401 Unauthorized The bearer token is missing or invalid.
Failure 403 Forbidden The bearer token is valid but does not correspond to the correct owner of the truck.
Failure 404 Not Found No truck with this truck_id exists

Response Examples

Success

Status: 204 No Content

Failure

Status: 401 Unauthorized

{
  "Error": "Invalid token."
}

Status: 403 Forbidden

{
  "Error": "You do not have access to this truck"
}

Status: 404 Not Found

{
  "Error": "No truck with this truck_id exists"
}

Delete All Trucks

Forbidden endpoint

DELETE /trucks

Protected?

Yes. The request must be accompanied by a valid bearer token.

Request

Path Parameters

None

Request Body

None

Response

No body

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Failure 401 Unauthorized The bearer token is missing or invalid.
Failure 405 Not Supported This endpoint is not supported

Response Examples

Failure

Status: 401 Unauthorized

{
  "Error": "Invalid token."
}

Status: 405 Not Supported

{
  "Error": "This endpoint is not supported"
}

Create a Load

Allows you to create a new load.

POST /loads

Protected?

No.

Request

Path Parameters

None

Request Body

Required

Request Body Format

application/json

Request JSON Attributes

Name Description Required?
item The supplier of the item Yes
quantity The items in the load. Yes
vendor The number of cases of the item Yes
weight The weight (lbs) of the load Yes

Request Body Example

{
  "item": "Organic strawberries",
  "quantity": 240,
  "vendor": "Driscoll's",
  "weight": 2160
}

Response

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Success 201 Created The input can contain extraneous attributes. Any attributes aside from the required attributes listed above will be ignored.
Failure 400 Bad Request The request is missing any of the required attributes.
Failure 406 Not Acceptable The client wants a media type other than JSON.
Failure 415 Unsupported Media Type The request is not JSON.

Response Examples

Success

Status: 201 Created

{
  "id": "6195449035751424",
  "item": "Organic strawberries",
  "quantity": 240,
  "vendor": "Driscoll's",
  "weight": 2160,
  "carrier": null,
  "self": "http://127.0.0.1:8080/loads/6195449035751424"
}

Failure

Status: 400 Bad Request

{
  "Error": "The request object is missing at least one of the required attributes"
}

Status: 406 Not Acceptable

{
  "Error": "This application only supports JSON responses"
}

Status: 415 Unsupported Media Type

{
  "Error": "Server only accepts application/json data."
}

View a Load

Allows you to get an existing load.

GET /loads/:load_id

Protected?

No.

Request

Path Parameters

Name Description
load_id ID of the load

Request Body

None

Response

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Success 200 OK
Failure 404 Not Found No load with this load_id exists
Failure 406 Not Acceptable The client wants a media type other than JSON.

Response Examples

Success

Status: 200 OK

{
  "carrier": {
    "id": "6687202524266496",
    "self": "http://127.0.0.1:8080/trucks/6687202524266496"
  },
  "weight": 1454,
  "quantity": 288,
  "item": "Blueberries",
  "vendor": "Driscoll's",
  "id": "5847751300481024",
  "self": "http://127.0.0.1:8080/loads/5847751300481024"
}

Failure

Status: 404 Not Found

{
  "Error": "No load with this load_id exists"
}

Status: 406 Not Acceptable

{
  "Error": "This application only supports JSON responses"
}

View All Loads

List all the loads.

GET /loads

Protected?

No.

Request

Path Parameters

None

Request Body

None

Response

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Success 200 OK The response contains a data property which is a list of all the loads in the Load kind.
Failure 406 Not Acceptable The client wants a media type other than JSON.

Response Examples

Success

Status: 200 OK

{
  "data": [
    {
      "carrier": null,
      "quantity": 432,
      "item": "Raspberries",
      "vendor": "Driscoll's",
      "weight": 2462.4,
      "id": "4870064809443328",
      "self": "http://127.0.0.1:8080/loads/4870064809443328"
    },
    {
      "weight": 2160,
      "carrier": null,
      "vendor": "Driscoll's",
      "quantity": 240,
      "item": "Organic strawberries",
      "id": "5110132711096320",
      "self": "http://127.0.0.1:8080/loads/5110132711096320"
    },
    {
      "weight": 880,
      "item": "Avocados",
      "vendor": "Taylor Farms",
      "carrier": null,
      "quantity": 160,
      "id": "5116145900191744",
      "self": "http://127.0.0.1:8080/loads/5116145900191744"
    },
    {
      "carrier": {
        "id": "6687202524266496",
        "self": "http://127.0.0.1:8080/trucks/6687202524266496"
      },
      "quantity": 288,
      "item": "Blueberries",
      "vendor": "Driscoll's",
      "weight": 1454,
      "id": "5679095853613056",
      "self": "http://127.0.0.1:8080/loads/5679095853613056"
    },
    {
      "vendor": "Driscoll's",
      "quantity": 360,
      "item": "Chocolate caramel apples",
      "weight": 3960,
      "carrier": null,
      "id": "5716561121771520",
      "self": "http://127.0.0.1:8080/loads/5716561121771520"
    }
  ]
}

Failure

Status: 406 Not Acceptable

{
  "Error": "This application only supports JSON responses"
}

Edit a Load (Put)

Allows you to overwrite all attributes of a load.

Side effect: carrier will be reset to null and the truck carrying the load (if applicable) will no longer contain this load in its loads property.

PUT /loads/:load_id

Protected?

No.

Request

Path Parameters

Name Description
load_id ID of the load

Request Body

Required

Request Body Format

application/json

Request JSON Attributes

Name Description Required?
item The supplier of the item Yes
quantity The items in the load. Yes
vendor The number of cases of the item Yes
weight The weight (lbs) of the load Yes

Request Body Example

{
  "item": "Blueberries",
  "quantity": 288,
  "vendor": "Hillcrest Produce",
  "weight": 1454
}

Response

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Success 200 OK The input can contain extraneous attributes. Any attributes aside from the required attributes listed above will be ignored.
Failure 400 Bad Request The request is missing any of the required attributes.
Failure 404 Not Found No load with this load_id exists.
Failure 406 Not Acceptable The client wants a media type other than JSON.
Failure 415 Unsupported Media Type The request is not JSON.

Response Examples

Success

Status: 200 OK

{
  "weight": 1450,
  "carrier": null,
  "vendor": "Hillcrest Produce",
  "quantity": 288,
  "item": "Blueberries",
  "id": "4899245085687808",
  "self": "http://127.0.0.1:8080/loads/4899245085687808"
}

Failure

Status: 400 Bad Request

{
  "Error": "The request object is missing at least one of the required attributes"
}

Status: 404 Not Found

{
  "Error": "No load with this load_id exists"
}

Status: 406 Not Acceptable

{
  "Error": "This application only supports JSON responses"
}

Status: 415 Unsupported Media Type

{
  "Error": "Server only accepts application/json data."
}

Edit a Load (Patch)

Allows you to overwrite any subset of attributes of a load, excluding carrier. The attributes that weren't explicitly overwritten in the request will remain unchanged.

Note: the relationship between a load and the truck carrying it will remain unchanged.

PATCH /loads/:load_id

Protected?

No.

Request

Path Parameters

Name Description
load_id ID of the load

Request Body

Required

Request Body Format

application/json

Request JSON Attributes

Name Description Required?
item The supplier of the item No
quantity The items in the load. No
vendor The number of cases of the item No
weight The weight (lbs) of the load No

Request Body Example

{
  "item": "Kale"
}

Response

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Success 200 OK The input can contain extraneous attributes. Any attributes aside from the required attributes listed above will be ignored.
Failure 400 Bad Request The request doesn't contain at least one of the attributes list above.
Failure 404 Not Found No load with this load_id exists.
Failure 406 Not Acceptable The client wants a media type other than JSON.
Failure 415 Unsupported Media Type The request is not JSON.

Response Examples

Success

Status: 200 OK

{
  "quantity": 135,
  "carrier": {
    "id": "6687202524266496",
    "self": "http://127.0.0.1:8080/trucks/6687202524266496"
  },
  "vendor": "Taylor Farms",
  "item": "Kale",
  "weight": 465.75,
  "id": "6225742111178752",
  "self": "http://127.0.0.1:8080/loads/6225742111178752"
}

Failure

Status: 400 Bad Request

{
  "Error": "The request object is missing at least one of the required attributes"
}

Status: 404 Not Found

{
  "Error": "No load with this load_id exists"
}

Status: 406 Not Acceptable

{
  "Error": "This application only supports JSON responses"
}

Status: 415 Unsupported Media Type

{
  "Error": "Server only accepts application/json data."
}

Delete a Load

Allows you to delete a load.

Side effect: If the load is on a truck, the deletion of the load will update the truck entity so that it no longer contains the load.

DELETE /loads/:load_id

Protected?

No.

Request

Path Parameters

Name Description
load_id ID of the load

Request Body

None

Response

No body

Response Body Format

Success: No body

Failure: application/json

Response Statuses

Outcome Status Code Notes
Success 204 No Content
Failure 404 Not Found No load with this load_id exists

Response Examples

Success

Status: 204 No Content

Failure

Status: 404 Not Found

{
  "Error": "No load with this load_id exists"
}

Delete All Loads

Forbidden endpoint

DELETE /loads

Protected?

No.

Request

Path Parameters

None

Request Body

None

Response

No body

Response Body Format

application/json

Response Statuses

Outcome Status Code Notes
Failure 405 Not Supported This endpoint is not supported

Response Examples

Failure

Status: 405 Not Supported

{
  "Error": "This endpoint is not supported"
}

Managing Loads: Load Assigned to Truck

A load is assigned to a truck.

Note: A load cannot be assigned to multiple trucks.

PUT /trucks/:truck_id/loads/:load_id

Protected?

Yes. The request must be accompanied by a valid bearer token.

Request

Path Parameters

Name Description
truck_id ID of the truck
load_id ID of the load

Request Body

None

Response

No body

Response Body Format

Success: No body

Failure: application/json

Response Statuses

Outcome Status Code Notes
Success 204 No Content Succeeds only if a truck exists with this truck_id, a load exists with this load_id and the load hasn't already been assigned to a truck.
Failure 401 Unauthorized The bearer token is missing or invalid.
Failure 403 Forbidden The bearer token is valid but does not correspond to the correct owner of the truck or the load has already been assigned to a truck.
Failure 404 Not Found The specified truck and/or load does not exist.

Response Examples

Success

Status: 204 No Content

Failure

Status: 401 Unauthorized

{
  "Error": "Invalid token."
}

Status: 403 Forbidden

{
  "Error": "You do not have access to this truck"
}

Status: 403 Forbidden

{
  "Error": "The load is already loaded on another truck"
}

Status: 404 Not Found

{
  "Error": "The specified truck and/or load does not exist"
}

Managing Loads: Load Removed from Truck

A load is removed from a truck.

DELETE /truck/:truck_id/loads/:load_id

Protected?

Yes. The request must be accompanied by a valid bearer token.

Request

Path Parameters

Name Description
load_id ID of the load
truck_id ID of the truck

Request Body

None

Response

No body

Response Body Format

Success: No body

Failure: application/json

Response Statuses

Outcome Status Code Notes
Success 204 No Content Succeeds only if a truck exists with this truck_id, a load exists with this load_id and the load is on the truck.
Failure 401 Unauthorized The bearer token is missing or invalid.
Failure 403 Forbidden The bearer token is valid but does not correspond to the correct owner of the truck.
Failure 404 Not Found No truck with this truck_id is loaded with the load with this load_id. This could be because no truck with this truck_id exists, or because no load with load_id exists, or even if both truck_id and load_id are valid, the load with this load_id is not on this truck with this truck_id

Response Examples

Success

Status: 204 No Content

Failure

Status: 401 Unauthorized

{
  "Error": "Invalid token."
}

Status: 403 Forbidden

{
  "Error": "You do not have access to this truck"
}

Status: 404 Not Found

{
  "Error": "No truck with this truck_id is loaded with the load with this load_id"
}

About

REST API that supports all CRUD operations for trucks and loads

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published