Sample operations with spray-json. Fuller code sample

103 views
Skip to first unread message

Dmitry G

unread,
Oct 4, 2011, 3:33:28 PM10/4/11
to spray-user
A total spray noob here but I'm sure lots of folks would benefit from
this..

Can someone post code expanding on e.g. the Color sample stuff on
https://github.com/spray/spray-json to illustrate how you go about
doing the various generic operations:

1. get color by name and return a string representation of the color
(or error if color not found)
2. get color by name and return a json representation of the color (or
error if color not found)
3. get all colors and return a string with all colors embedded
4. get all colors and return a json representation of all the colors
5. add a color and return a status code (e.g. 1 for added
successfully, 0 if already existed)
6. same as 5 except return the result as json
7. bulk init of the color set by sending in a set of colors to one
init method
8. same as 7 except post json

this would help a great deal, thanks.

Mathias

unread,
Oct 4, 2011, 5:53:44 PM10/4/11
to spray...@googlegroups.com
Dmitry,

I'm not sure I really understand your question(s).
"Get color by name?"
"Get all colors?"

Could you supply a little more context as to what you are trying to achieve with spray-json?

Cheers,
Mathias

---
mat...@spray.cc
http://www.spray.cc

Dmitry G

unread,
Oct 6, 2011, 5:38:40 PM10/6/11
to spray-user
Mathias,

I think I got this stuff to work but generally I was fishing for a
more cohesive set of spray usage samples, especially when it comes to
json.

Presumably, the most popular use-case tends to be that of a "manager"
service of some sort and the "managed" objects. Some examples of this
would be a Palette and Color's as well as an AddressBook and Person's.

This asks for a set of CRUD methods: create, read, update, delete;
most importantly create and read. Furthermore, this breaks down to
more use-cases:

- create one object (via parameters, json, or xml)
- get one object back from the service (via json or xml)
- write multiple objects (via json, xml)
- read multiple objects at a time (via json, xml)

So, basically, along the lines of:
- addPerson(String name, String phoneNum), return something e.g.
status code
- addPerson(json), return something e.g. status code
- addPerson(xml), return something e.g. status code
- getPerson(String name), return String representation
- getPersonAsJson(String name), return json representation of the
person
- getPersonAsXml(String name), return xml representation of the person
- savePersons(json), return the count of added persons
- savePersons(xml), return the count of added persons
- getAllPersonsAsJson, return json representation of the whole address
book
- getAllPersonsAsXml, return xml representation of the whole address
book

In addition, it's interesting to bring in more examples of nestedness.
Maybe it would be a MailingList containing Person's...

The current samples don't seem to have much of this stuff.

Thanks,
- Dmitry

Mathias

unread,
Oct 8, 2011, 8:17:50 AM10/8/11
to spray...@googlegroups.com
Dmitry,

yes, I agree.
Having such examples would be a nice addition to the spray / spray-json documentation.
We'd be extremely happy if you (or someone else) would be able to contribute them...
If you supply a first cut we might be able to pick it up from there.

Cheers,
Mathias

---
mat...@spray.cc
http://www.spray.cc

Reply all
Reply to author
Forward
0 new messages