Object Graph Retrival DSL ..

11Mar09

Often in a query based api’s ( for example  REST based apis )  there is a need for providing a capability for the client to specify the field and depth  while retrieving an object graph ..

For example, Windows Live contact Api

let you specify Field and Depth Filtering via the query param Filter , for example a request like

https://livecontacts.services.live.com/users/@L@<lid>/rest/livecontacts&Filter=LiveContacts(Contact(ID,CID),Tag)

Would retrive live contacts contact with id , CID and tag for live contact .

You could make this infinitely recursive to pick and choose fields you want at any graph depth .

Here is the  antlr grammer for doing just that .. Instructions for how to generate code is available on antlr website

grammar Response;

options {output=AST;}
tokens {
   FIELDSHORTCUT;
   STAR;
}
response:  root (',' root)* -> root+ ;
root 	:fieldshortcut|'*'| (nodewithchildren);
nodewithchildren: (ID LPAREN response RPAREN) -> ^(ID response)
	|ID -> ^(ID STAR)
	|ID '()'-> ^(ID) ;
fieldshortcut
	:	'{'ID'}' -> ^(FIELDSHORTCUT ID);	

ID  :   ('a'..'z'|'A'..'Z')+ ;
INT :   '0'..'9'+ ;
LPAREN 	:	'(';
RPAREN 	:	')';

NEWLINE:'\r'? '\n' ;
WS  :   (' '|'\t')+ { $channel=HIDDEN;} ;
About these ads


One Response to “Object Graph Retrival DSL ..”

  1. Their just like you understand my head! You peer to be aware of a great deal close to this, such as you published a e-book within it or something that is. I believe you may possibly utilize several g. d. in order to tension what it’s all about residence slightly, but instead of this, that is definitely outstanding web site. A great examine. I’ll certainly return to their office.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: