Creating resources

38 views
Skip to first unread message

Jørn Wildt

unread,
Dec 30, 2011, 7:49:28 AM12/30/11
to OpenRasta
I am trying to implement the following:

1) At /documents there shall be an HTML page with a description of how
to create a document (this URL is *not* the list of all documents). It
could also include an HTML form for actually letting someone try it
through the browser.

2) A new document is created by posting either XML or form-urlencoded
data to /documents

3) When the new resource (document) is created, the server returns
status "Created", a link to the new document and a copy of the
document.

How am I supposed to configure this?

I am trying:

ResourceSpace.Has.ResourcesOfType<Document>()
.AtUri("/documents")
.HandledBy<DocumentsHandler>()
.RenderedByAspx("~/Views/Documents/CreateDocument.aspx");

But there are in fact no "Document" at that URL - so what should the
argument to ResourceOfType be?

It further more seems to conflict with another configuration for /
document/{id} which has a single Document resource:

ResourceSpace.Has.ResourcesOfType<Document>()
.AtUri("/documents/{id}")
.HandledBy<DocumentHandler>()
.TranscodedBy<DocumentXmlCodec>();

/Jørn

Neil Mosafi

unread,
Dec 30, 2011, 8:16:20 AM12/30/11
to open...@googlegroups.com
Create a class for it, then you could do something like ResourceSpace.Has.ResourcesOfType<DocumentCreationInstruction>()

I think you might be able to do avoid creating the class and use ResourceSpace.Has.ResourcesNamed() but I am not sure how that works.

Neil

Bob Gregory

unread,
Jan 3, 2012, 4:28:27 AM1/3/12
to open...@googlegroups.com
What about 

  ResourceSpace.Has.ResourcesOfType<Document>()

         .AtUri("/documents/{id}")
         .HandledBy<DocumentHandler>()
         .TranscodedBy<DocumentXmlCodec>()

         .And.AtUri("/documents")
         .HandledBy<DocumentCreationHandler>();

Then just make your GET on DocumentCreationHandler return string, and you're away.

Occasionally, when using a setup like this, I get conflicts between URIs, and I've found that named URIs offer a good way to disambiguate, as in


  ResourceSpace.Has.ResourcesOfType<Document>()

         .AtUri("/documents/{id}").Named("document-uri")

         .HandledBy<DocumentHandler>()
         .TranscodedBy<DocumentXmlCodec>()

         .And.AtUri("/documents").Named("document-creation-uri")
         .HandledBy<DocumentCreationHandler>();


public class DocumentCreationHandler
{
   [HttpOperation(ForUriName = "document-creation-uri", Method="GET")]
   public string GetInstructions() {}

   [HttpOperation(ForUriName = "document-creation-uri", Method="POST")]
   public OperationResult CreateDocument(Document doc) {}
}
--
Q. How many members of a demographic group does it take to perform a specified task?

A. A finite number; one to perform the task, and the remainder to act in a manner stereotypical of the group in question.

Jørn Wildt

unread,
Jan 6, 2012, 3:20:31 PM1/6/12
to OpenRasta
Thanks for the input. Making up a new class like
"CreateDocumentDescriptor" solved it for me.

/Jørn
Reply all
Reply to author
Forward
0 new messages