2012/03/01

Five Step Tango

You know how you can often discover new things from re-reading (re-hearing) an old story ? I'm sitting in on a NetKernel training in the Twin Cities this week and while I have been in a similar training two or three times already, the following never took hold in my mind ...

Writing a physical endpoint contains five steps.

Now, such a statement is rather important given that there's nothing but spaces and endpoints (within those spaces) in NetKernel! So I don't know how I missed it in the previous sessions. Must be my selective hearing impediment.

Step 1. What is it you want ?
From the point of view of the physical endpoint that just got resolved to, this is rather important information. And it is available :
context.getThisRequest();

Step 2. What do I need to satisfy this request ?
Well, there are several possibilities here. Arguments passed to the request for example :
context.getThisRequest.getArgumentValue("...");
Also, subrequests may be needed :
context.createRequest(...);

Step 3. Add value
Be creative here!

Step 4. Prepare a response
Once the endpoint has done what it is supposed to do, it is time to create a response.
context.createResponseFrom(...);

Step 5. Set metadata on the response
This is an optional step (the five step tango also really has only four steps), most of the time the defaults will be fine. But you can :
response = context.createResponseFrom(...);
response.setMimeType("text/plain");


There, that is all there is to writing a physical endpoint. Enjoy!