0

I am trying to design a JSON object that would work with Jersey and Jackson.

Am fairly new to JSON / Restful programming, so I am wondering if the following is viable.

{
"name": "myservice",

"orders": [
    {
        "name": "iphone",
        "description": "iPhone 5",
        "providers": [
            {
                "name": "a",
                "description": "AT&T",
                "pricing": ["$40", "$70", "$120"]
            },
            {
                "name": "b",
                "description": "Verizon",
                "pricing": ["$45", "$60", "$85"]
            }
        ]
    },
    {
        "name": "galaxy3",
        "description": "Samsung Galaxy 3",
        "providers": [
            {
                "name": "a",
                "description": "AT&T",
                 "pricing": ["$45", "$60", "$85"]

            }
        ]
    }
]
}

Get all information regarding iPhone's Verizon provider:

 curl GET -H'Content-Type: application/json' https://mydomain/myservice/iphone/b 

would return:

{
   "name": "b",
   "description": "Verizon",
   "pricing": ["$45", "$60", "$85"]
}

Get list of pricing for iPhone's AT&T provider:

curl GET -H'Content-Type: application/json' https://mydomain/myservice/iphone/a?pricing 

Would return:

{

   ["$40", "$70", "$120"]

}

Any examples or feedback will be greatly appreciated!

PacificNW_Lover
  • 4,746
  • 31
  • 90
  • 144

1 Answers1

0

Here is a good discussion about defining a REST API: REST Complex/Composite/Nested Resources

Here is what I would change in your json: 1. orders -> order, because resources are declared as singular nouns 2. providers -> provider, because of the same

This is how I would call from a client if I know what I need to get (using composite resources):

  1. https://<mydomain>/myservice/order/iphone/provider/b
  2. https://<mydomain>/myservice/order/iphone/provider/a/pricing

In case you need to search for an order, you can define the request like:

  1. https://<mydomain>/myservice/order?name=iphone -> it would return the 1st element in the "order" list

The assumption is that "name" is a key for the respective resouces (order and provider)

Community
  • 1
  • 1
tavi
  • 660
  • 7
  • 16