A template example

185 views
Skip to first unread message

David Mitchell

unread,
Feb 16, 2012, 2:51:42 PM2/16/12
to Collection+JSON
Hi Mike,

I am still trying to learn Collection+JSON. I created a template.
See the example below.

Some partners have "targets" and some do not. Moreover, partner 99
has three goals, but partner 85 only has one goal. Some partners do
not have any goals. So, the template, that I designed, varries from
partner to partner. The template below was returned when a call was
made for "partner=99" and "client=1". A different template would be
returned if the request was made for "partner=85" and "client=2".

My question is, should templates be generic or should they be specific
to a particular partner, as I have designed?

"template" : {
"data" : [{
"name" : "partner",
"value" : "99",
"prompt" : "Partner ID"
}, {
"name" : "client",
"value" : "1",
"prompt" : "Client ID"
}, {
"name" : "camper",
"value" : "1",
"prompt" : "Camper ID"
}, {
"name" : "time",
"options" : [{
"value" : ""
}
]
}, {
"name" : "target",
"value" : ""
}, {
"name" : "signal",
"options" : [{
"value" : "11"
}, {
"value" : "12"
}, {
"value" : "13"
}
]
}, {
"name" : "goal",
"options" : [{
"value" : "11"
}, {
"value" : "12"
}, {
"value" : "13"
}
]
}, {
"name" : "result",
"options" : [{
"value" : "0"
}, {
"value" : "1"
}
]
}
]
}

Thank you for your help.

David

mca

unread,
Feb 16, 2012, 3:23:08 PM2/16/12
to collect...@googlegroups.com
David:

interesting idea!

yes, you are free to pass templates that match the client's needs at
the point in time. I would say it is important to make sure the server
knows how to return the "right" template at the "right" time. also,
the current design does not have an accommodation to allow clients to
_select_ from a list of templates. but I think you are not worried
about that at this point, right?

mca
http://amundsen.com/blog/
http://twitter.com@mamund
http://mamund.com/foaf.rdf#me

David Mitchell

unread,
Feb 16, 2012, 5:29:07 PM2/16/12
to Collection+JSON

Hi Mike,

At the moment, each camper only has one template. We only have to
worry about selecting multiple templates when an "admin" user is
logged in, and can see all campers. But, in this case, I think that
the admin can select a particular camper and then would be presented
with the appropriate template.

David

mca

unread,
Feb 16, 2012, 5:34:25 PM2/16/12
to collect...@googlegroups.com
sounds quite workable.

please keep me posted on your progress with this implementation. it
sounds like a very good test of the media type design.

Vikas

unread,
Aug 21, 2012, 6:10:48 AM8/21/12
to collect...@googlegroups.com
Hi Mike

thank you for CJ - it has been very useful for us to use in our API. Devin and me are now sitting reading the comments in this group and couldn't find an answer to our use case.

We need basically options in our template to represent a list for selection in the client, namely, a normal <select> tag with<options>. 
Here is our example, is this a proper way to extend CJ?

template: { 
  data: [{ 
      name: "name", 
      value: "Joe",
      prompt: "Client name" 
    }, {
      name: "country", 
      value: "Germany",
      prompt: "Country",
      multiple: "false"
      options: [
                {prompt: "Germany", value: "de"},
                {prompt: "Poland", value: "pl"}
               ]
    }
]}

We also thought to reference the option using rel and link, which might be versatile but would be harder for the client to implement and would also require another response/request cycle.


cheers
Vikas and Devin

mca

unread,
Aug 21, 2012, 6:38:14 AM8/21/12
to collect...@googlegroups.com
glad CJ is proving helpful.

yes, this has come up before and i've used a very similar design, but haven't logged it as an extension on the github yet.

please feel free to write up an extension (see the repo for examples there; it's quite simple) and post it here where we can discuss it and then add it to the repo as an official extension.

Cheers

BTW - would love to hear more about your project that uses CJ.

Vikas

unread,
Aug 23, 2012, 9:09:36 AM8/23/12
to collect...@googlegroups.com
Hi Mike

good feedback from you and Deving discussed in pull issue on Github

here is the current state in the pull request, which were are currently starting to use:
 "template" : {
      "data" : [
        { "name" : "username", "value" : "", "prompt" : "User name", "required" : "true" },
        { "name" : "country", "value" : "", "prompt" : "Country", "multiple" : "false",  "options" : [ { "text" : "Germany", "value" : "de" }, { "text" : "Poland", "value" : "pl" } ] },
        { "name" : "talents", "value" : "", "prompt" : "Talents", "required" : "true", "multiple" : "true",  "options" : [ { "text" : "Swimming", "value" : "swimming" }, { "text" : "Climbing", "value" : "climbing" }, { "text" : "Socializing", "value" : "socializing" } ] }
      ]
    }
And Values if multiple is true.
{"name" : "country", "value" : ["Germany", "Poland"], ...}

cheers
Vikas
@chatmasala

mca

unread,
Aug 23, 2012, 9:21:13 AM8/23/12
to collect...@googlegroups.com
Vikas:

While I find the template design makes sense, I am unclear on the details of the resulting "item." To help me, please show the following:
1 - the actual state that is transferred from client to server (via POST or PUT)
2 - the resulting "item" that is returned from server to client

Finally, as mentioned in the github comments, using the "value" property to hold an array is currently forbidden by the specification. I suggest you use the "value-types" extension that is already registered and render arrays using the "array" property of the data element.

Mike Amundsen

unread,
Aug 27, 2012, 8:55:20 PM8/27/12
to collect...@googlegroups.com
Are you still interested in registering an extension?

MrDevin

unread,
Aug 29, 2012, 7:21:55 AM8/29/12
to collect...@googlegroups.com
Hi, 
We are still interested in registering an extension but have been busy the last couple of days. We plan to discuss this later today and get back to you asap. 
Thanks
Devin

mca

unread,
Aug 29, 2012, 11:33:08 AM8/29/12
to collect...@googlegroups.com
sounds fine. just wanted to make sure we didn't loose you!

post when you can

Cheers.

Vikas

unread,
Aug 30, 2012, 12:31:15 PM8/30/12
to collect...@googlegroups.com
Hi Mike

Devin just committed what he suggested. We definitely should use value-types, therefore changed value into array.

PUT/POST requests 
{"username":JDoe,"country":"germany","talents":["swimming","climbing"]}

items:
"data" : [
          {"name" : "username", "value" : "JDoe", "prompt" : "User name"},
          {"name" : "country", "value" : "Germany", "prompt" : "Country"},
          {"name" : "talents", "array" : ["swimming", "climbing"], "prompt" : "Talents"}
        ]

Hope our suggestions help to register this extension.


Thanks for waiting :) - when I was occupied with a hackathon for SocialQuest at Campus Party in Berlin

Vikas

mca

unread,
Aug 30, 2012, 1:08:37 PM8/30/12
to collect...@googlegroups.com
no problem on the wait; good stuff takes time.

looks pretty good from here. I made some comments on the pull request. Mainly, I'd like to see the stuff in this email (POST/PUT body and resulting "item") included in the extension doc.

Shore up the doc a bit and I think we have a winner.

Thanks.

Vikas

unread,
Sep 19, 2012, 3:13:26 PM9/19/12
to collect...@googlegroups.com
Hi Mike,

some not so good stuff also take time. I just dislocated my elbow and a cast is keeping my arm tight and together :)
But I'am back with a suggestion on gist: https://gist.github.com/3415015

I hope it's clear and transparent for readers now.

Vikas

mca

unread,
Sep 19, 2012, 3:15:03 PM9/19/12
to collect...@googlegroups.com
yeesh!

just replied to the previous post. take care of yourself!

Johnathon Wright

unread,
Dec 4, 2013, 12:03:54 AM12/4/13
to collect...@googlegroups.com
My impression is that this pull request is still open... where are we on this issue?

My team is generally enjoying collection+json... thanks to all who helped with it.

jw

mca

unread,
Dec 9, 2013, 3:50:52 PM12/9/13
to collect...@googlegroups.com
Vikas, Devin:

is this up and running for you? any examples/client code we can check out?


mca

--
You received this message because you are subscribed to the Google Groups "Collection+JSON" group.
To unsubscribe from this group and stop receiving emails from it, send an email to collectionjso...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages