Skip to content

Instantly share code, notes, and snippets.

@akshitmahajan
Forked from hjr3/e-commerce.md
Last active August 29, 2015 14:14
Show Gist options
  • Save akshitmahajan/c6b479e0d6480ab2f60d to your computer and use it in GitHub Desktop.
Save akshitmahajan/c6b479e0d6480ab2f60d to your computer and use it in GitHub Desktop.

Revisions

  1. @hjr3 hjr3 revised this gist Apr 4, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion e-commerce.md
    Original file line number Diff line number Diff line change
    @@ -137,7 +137,7 @@ address to the payment calculation.
    "subtotal":49,
    "tax":0,
    "freight":5,
    "total":54,
    "total":44,
    "_embedded":{
    "http://www.example.com/rels/coupon":[
    {
  2. @hjr3 hjr3 revised this gist Apr 4, 2012. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions e-commerce.md
    Original file line number Diff line number Diff line change
    @@ -147,7 +147,11 @@ address to the payment calculation.
    }
    ],
    "http://example.com/rels/shipping":{
    "shipping_id":135451,
    "_links":{
    "self":{
    "href":"/shipping/135451"
    }
    },
    "first_name":"Heman",
    "last_name":"Radtke",
    "address":"1234 Day St.",
    @@ -157,7 +161,11 @@ address to the payment calculation.
    "country_iso":"US"
    },
    "http://example.com/rels/billing":{
    "billing_id":"230266",
    "_links":{
    "self":{
    "href": "/billing/135451"
    }
    },
    "first_name":"Herman",
    "last_name":"Radtke",
    "address":"1234 Day St.",
  3. @hjr3 hjr3 revised this gist Apr 3, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion e-commerce.md
    Original file line number Diff line number Diff line change
    @@ -165,7 +165,7 @@ address to the payment calculation.
    "state":"CA",
    "zipcode":"90015",
    "country_iso":"US",
    "card_number":"111",
    "card_number":"1111",
    "card_type":"mastercard",
    "card_exp_year":"2015",
    "card_exp_month":"01"
  4. @hjr3 hjr3 revised this gist Apr 3, 2012. 1 changed file with 40 additions and 40 deletions.
    80 changes: 40 additions & 40 deletions e-commerce.md
    Original file line number Diff line number Diff line change
    @@ -50,46 +50,46 @@ provided to the payment calculation URI.
    Content-Type: application/hal+json
    Etag: 372b753d68c06990ea22b04b9c9fd4f8

    {
    "_links":{
    "self":{
    "href":"/member/109087/cart"
    },
    "http://example.com/rels/payment":{
    "href":"/payment"
    }
    },
    "_embedded":{
    "http://example.com/rels/cart-item":[
    {
    "_links":{
    "self":{
    "href":"/member/109087/cart/14418796"
    }
    },
    "id":"14418796",
    "quantity":1,
    "expire_time":"2009-09-11T08:00:00-07:00",
    "_embedded":{
    "http://example.com/rels/sku":[
    {
    "_links":{
    "self":{
    "href":"/skus/654654"
    },
    "http://example.com/images/cart/item":"http://example.com/product/6895/thumbnail.jpg"
    },
    "color":"Black",
    "size":"S",
    "returnable":false,
    "price":49
    }
    ]
    }
    }
    ]
    }
    }
    {
    "_links":{
    "self":{
    "href":"/member/109087/cart"
    },
    "http://example.com/rels/payment":{
    "href":"/payment"
    }
    },
    "_embedded":{
    "http://example.com/rels/cart-item":[
    {
    "_links":{
    "self":{
    "href":"/member/109087/cart/14418796"
    }
    },
    "id":"14418796",
    "quantity":1,
    "expire_time":"2009-09-11T08:00:00-07:00",
    "_embedded":{
    "http://example.com/rels/sku":[
    {
    "_links":{
    "self":{
    "href":"/skus/654654"
    },
    "http://example.com/images/cart/item":"http://example.com/product/6895/thumbnail.jpg"
    },
    "color":"Black",
    "size":"S",
    "returnable":false,
    "price":49
    }
    ]
    }
    }
    ]
    }
    }


    #### Calculate Payment ####
  5. @hjr3 hjr3 revised this gist Apr 3, 2012. 1 changed file with 38 additions and 37 deletions.
    75 changes: 38 additions & 37 deletions e-commerce.md
    Original file line number Diff line number Diff line change
    @@ -50,45 +50,46 @@ provided to the payment calculation URI.
    Content-Type: application/hal+json
    Etag: 372b753d68c06990ea22b04b9c9fd4f8

    {
    "_links":
    "self": {
    "href": "/member/109087/cart"
    {
    "_links":{
    "self":{
    "href":"/member/109087/cart"
    },
    "http://example.com/rels/payment":{
    "href":"/payment"
    }
    },
    "_embedded":{
    "http://example.com/rels/cart-item":[
    {
    "_links":{
    "self":{
    "href":"/member/109087/cart/14418796"
    }
    },
    "http://example.com/rels/payment": {
    "href": "/payment"
    }
    },
    "_embedded": {
    "http://example.com/rels/cart-item": [
    {
    "_links": {
    "self": {
    "href": "/member/109087/cart/14418796"
    },
    "id":"14418796",
    "quantity":1,
    "expire_time":"2009-09-11T08:00:00-07:00",
    "_embedded":{
    "http://example.com/rels/sku":[
    {
    "_links":{
    "self":{
    "href":"/skus/654654"
    },
    "id": "14418796",
    "quantity": 1,
    "expire_time": "2009-09-11T08:00:00-07:00",
    "_embedded": {
    "http://example.com/rels/sku": [{
    "_links": {
    "self": {
    "href": "/skus/654654"
    },
    "image_url": "http://example.com/product/6895/thumbnail.jpg",
    },
    "color":"Black",
    "size":"S",
    "returnable": false,
    "price": 49,
    }]
    }
    }
    }
    ]
    }
    }
    "http://example.com/images/cart/item":"http://example.com/product/6895/thumbnail.jpg"
    },
    "color":"Black",
    "size":"S",
    "returnable":false,
    "price":49
    }
    ]
    }
    }
    ]
    }
    }


    #### Calculate Payment ####
  6. @hjr3 hjr3 revised this gist Apr 3, 2012. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions e-commerce.md
    Original file line number Diff line number Diff line change
    @@ -4,12 +4,16 @@ These examples are type 3 RESTful API requests and responses. The JSON-HAL speci

    Some of the examples are based on my work as architect of the RESTful API at http://www.hautelook.com. All proprietary information has been removed.

    Relevant links:
    ### Relevant links ###

    * JSON-HAL specification: http://stateless.co/hal_specification.html#media_type_identifiers
    * JSON linking with HAL: http://blog.stateless.co/post/13296666138/json-linking-with-hal
    * Semantic RESTful documentation: http://geekswithblogs.net/michelotti/archive/2011/06/06/documenting-link-relations-with-web-api.aspx

    ### Examples ###

    #### Add Item to Cart ####

    A POST request to /member/109087/cart will create a cart resource for the member (if one did not exist) and add the inventory item to the cart. The
    Location header links to the cart resource that was created or updated. It is optional to add the JSON-HAL representation of that resource as the
    POST response, but not required.
    @@ -31,6 +35,7 @@ POST response, but not required.
    Location: /member/109087/cart/14418796


    #### Get Cart Contents ####
    A GET request to /member/109087/cart will respond with the cart resource and list the contents of the cart items as embedded resources. A link is
    provided to the payment calculation URI.

    @@ -40,7 +45,6 @@ provided to the payment calculation URI.
    Content-type: application/json
    Accept: application/hal+json


    HTTP/1.1 200 OK
    Date: Mon, 20 Jun 2011 21:15:00 GMT
    Content-Type: application/hal+json
    @@ -87,6 +91,8 @@ provided to the payment calculation URI.
    }


    #### Calculate Payment ####

    A GET request to /payment will calculate the total amount owed by the member based on the contents in the members cart. The calculation results,
    along with any discounts (coupons, giftcards, etc) are sent back for the member to review. The relation to http://example.com/payment/coupon allows
    the member to add and remove any coupons from the calculation.
    @@ -168,6 +174,7 @@ address to the payment calculation.
    }


    #### Place Order ####
    A POST request to /orders will create an order resource based on the contents of the members cart.

    POST /orders HTTP/1.1
  7. @hjr3 hjr3 revised this gist Apr 3, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions e-commerce.md
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@ These examples are type 3 RESTful API requests and responses. The JSON-HAL speci
    Some of the examples are based on my work as architect of the RESTful API at http://www.hautelook.com. All proprietary information has been removed.

    Relevant links:

    * JSON-HAL specification: http://stateless.co/hal_specification.html#media_type_identifiers
    * JSON linking with HAL: http://blog.stateless.co/post/13296666138/json-linking-with-hal
    * Semantic RESTful documentation: http://geekswithblogs.net/michelotti/archive/2011/06/06/documenting-link-relations-with-web-api.aspx
  8. @hjr3 hjr3 revised this gist Apr 3, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions e-commerce.md
    Original file line number Diff line number Diff line change
    @@ -5,9 +5,9 @@ These examples are type 3 RESTful API requests and responses. The JSON-HAL speci
    Some of the examples are based on my work as architect of the RESTful API at http://www.hautelook.com. All proprietary information has been removed.

    Relevant links:
    * JSON-HAL specification: http://stateless.co/hal_specification.html#media_type_identifiers
    * JSON linking with HAL: http://blog.stateless.co/post/13296666138/json-linking-with-hal
    * Semantic RESTful documentation: http://geekswithblogs.net/michelotti/archive/2011/06/06/documenting-link-relations-with-web-api.aspx
    * JSON-HAL specification: http://stateless.co/hal_specification.html#media_type_identifiers
    * JSON linking with HAL: http://blog.stateless.co/post/13296666138/json-linking-with-hal
    * Semantic RESTful documentation: http://geekswithblogs.net/michelotti/archive/2011/06/06/documenting-link-relations-with-web-api.aspx

    A POST request to /member/109087/cart will create a cart resource for the member (if one did not exist) and add the inventory item to the cart. The
    Location header links to the cart resource that was created or updated. It is optional to add the JSON-HAL representation of that resource as the
    @@ -178,4 +178,4 @@ A POST request to /orders will create an order resource based on the contents of
    HTTP/1.1 201 Created
    Date: Mon, 20 Jun 2011 21:15:00 GMT
    Content-Type: application/hal+json
    Location: /orders/453435
    Location: /orders/453435
  9. @hjr3 hjr3 created this gist Apr 3, 2012.
    181 changes: 181 additions & 0 deletions e-commerce.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,181 @@
    # Examples of RESTful API calls for E-commerce platforms #

    These examples are type 3 RESTful API requests and responses. The JSON-HAL specification is used to implement HATEOAS.

    Some of the examples are based on my work as architect of the RESTful API at http://www.hautelook.com. All proprietary information has been removed.

    Relevant links:
    * JSON-HAL specification: http://stateless.co/hal_specification.html#media_type_identifiers
    * JSON linking with HAL: http://blog.stateless.co/post/13296666138/json-linking-with-hal
    * Semantic RESTful documentation: http://geekswithblogs.net/michelotti/archive/2011/06/06/documenting-link-relations-with-web-api.aspx

    A POST request to /member/109087/cart will create a cart resource for the member (if one did not exist) and add the inventory item to the cart. The
    Location header links to the cart resource that was created or updated. It is optional to add the JSON-HAL representation of that resource as the
    POST response, but not required.

    POST /member/109087/cart HTTP/1.1
    Host: api.example.com
    Authorization: Basic username:password
    Content-type: application/json
    Accept: application/hal+json

    {
    "inventory_id": 12345,
    "quantity": 1
    }

    HTTP/1.1 201 Created
    Date: Mon, 20 Jun 2011 21:15:00 GMT
    Content-Type: application/hal+json
    Location: /member/109087/cart/14418796


    A GET request to /member/109087/cart will respond with the cart resource and list the contents of the cart items as embedded resources. A link is
    provided to the payment calculation URI.

    GET /member/109087/cart HTTP/1.1
    Host: api.example.com
    Authorization: Basic username:password
    Content-type: application/json
    Accept: application/hal+json


    HTTP/1.1 200 OK
    Date: Mon, 20 Jun 2011 21:15:00 GMT
    Content-Type: application/hal+json
    Etag: 372b753d68c06990ea22b04b9c9fd4f8

    {
    "_links":
    "self": {
    "href": "/member/109087/cart"
    },
    "http://example.com/rels/payment": {
    "href": "/payment"
    }
    },
    "_embedded": {
    "http://example.com/rels/cart-item": [
    {
    "_links": {
    "self": {
    "href": "/member/109087/cart/14418796"
    },
    },
    "id": "14418796",
    "quantity": 1,
    "expire_time": "2009-09-11T08:00:00-07:00",
    "_embedded": {
    "http://example.com/rels/sku": [{
    "_links": {
    "self": {
    "href": "/skus/654654"
    },
    "image_url": "http://example.com/product/6895/thumbnail.jpg",
    },
    "color":"Black",
    "size":"S",
    "returnable": false,
    "price": 49,
    }]
    }
    }
    }
    ]
    }
    }


    A GET request to /payment will calculate the total amount owed by the member based on the contents in the members cart. The calculation results,
    along with any discounts (coupons, giftcards, etc) are sent back for the member to review. The relation to http://example.com/payment/coupon allows
    the member to add and remove any coupons from the calculation.

    The choice of shipping and billing addresses to be used during payment are sent back as well. The relations http://example.com/rels/billing and
    http://example.com/rels/shipping provide allow the member to add, remove and retrieve their billing and shipping addresses. The relations
    http://example.com/rels/payment/billing and http://example.com/rels/payment/shipping allow the member to apply a different shipping or billing
    address to the payment calculation.

    GET /payment HTTP/1.1
    Host: api.example.com
    Authorization: Basic username:password
    Content-type: application/json
    Accept: application/hal+json

    HTTP/1.1 200 OK
    Date: Mon, 20 Jun 2011 21:15:00 GMT
    Content-Type: application/hal+json
    Cache-Control: private, no-store

    {
    "_links":{
    "self":{
    "href":"/payment"
    },
    "http://example.com/rels/billing":{
    "href":"/member/109087/billing"
    },
    "http://example.com/rels/shipping":{
    "href":"/member/109087/shipping"
    },
    "http://example.com/rels/payment/coupon":{
    "href":"/payment/coupon"
    },
    "http://example.com/rels/payment/billing":{
    "href":"/payment/billing"
    },
    "http://example.com/rels/payment/shipping":{
    "href":"/payment/shipping"
    },
    "subtotal":49,
    "tax":0,
    "freight":5,
    "total":54,
    "_embedded":{
    "http://www.example.com/rels/coupon":[
    {
    "type":"dollarOff",
    "amount":"10",
    "code":"A0318A97"
    }
    ],
    "http://example.com/rels/shipping":{
    "shipping_id":135451,
    "first_name":"Heman",
    "last_name":"Radtke",
    "address":"1234 Day St.",
    "city":"Los Angeles",
    "state":"CA",
    "zipcode":"90015",
    "country_iso":"US"
    },
    "http://example.com/rels/billing":{
    "billing_id":"230266",
    "first_name":"Herman",
    "last_name":"Radtke",
    "address":"1234 Day St.",
    "city":"Los Angeles",
    "state":"CA",
    "zipcode":"90015",
    "country_iso":"US",
    "card_number":"111",
    "card_type":"mastercard",
    "card_exp_year":"2015",
    "card_exp_month":"01"
    }
    }
    }
    }


    A POST request to /orders will create an order resource based on the contents of the members cart.

    POST /orders HTTP/1.1
    Host: api.example.com
    Authorization: Basic username:password
    Content-type: application/json
    Accept: application/hal+json

    HTTP/1.1 201 Created
    Date: Mon, 20 Jun 2011 21:15:00 GMT
    Content-Type: application/hal+json
    Location: /orders/453435