librelist archives

« back to archive

Sink Adapters

Sink Adapters

From:
Geoff.Jukes
Date:
2014-12-12 @ 07:53
Hi,

Please forgive this stupid question (I'm new to API development). But what
is a 'sink' adapter? Can someone link me to some documentation on what 
'sinks' are in this context? (you try googling it! Lol)

It appears to be a method by which I can forward a request to a different 
service (web or otherwise). Basically allowing me to create a convenient 
interface layer for abstract systems - is that about right? In principle, 
a kind of reverse proxy for HTTP requests.

If so - then awesome! This is *exactly* what I have been looking for! I 
need to write a REST API that returns data that actually originates from 
an external SOAP service (among other things).

Can someone provide me with a contrived example that actually forwards 
something? The example code just returns a 503. Or is it as simple as 
using other tools to make the forward request? (such as suds, boto, etc)

Many thanks,

Geoff

Re: [falcon] Sink Adapters

From:
Kurt Griffiths
Date:
2014-12-16 @ 16:29
Hi Geoff, you’re on the right track. In the Falcon framework, a sink is 
something that can “drain” (capture) all requests, or a subset thereof, 
that weren’t routed. It is useful when you want to dynamically map URLs 
and methods (e.g., GET, POST, DELETE) to operations on the backend. You 
can certainly use sinks to implement a smart proxy, as you pointed out. In
some cases, this is more convenient than having to explicitly map all 
operations using resource classes and responders (e.g., on_get, on_post, 
on_delete).

You can do anything you like inside a sink function (calling to one or 
more backend services using the client library of your choice, validating,
logging, etc.). Before returning you just need to update the resp object, 
or raise an instance of falcon.HTTPError. Here is some code that outlines 
how this might work:

https://gist.github.com/kgriffs/01bf00ebba1ad83d98af

Hope that helps!

-Kurt

From: "Geoff.Jukes" 
<geoff.jukes@blackstoneaudio.com<mailto:geoff.jukes@blackstoneaudio.com>>
Reply-To: "falcon@librelist.com<mailto:falcon@librelist.com>" 
<falcon@librelist.com<mailto:falcon@librelist.com>>
Date: Friday, December 12, 2014 at 1:53 AM
To: "falcon@librelist.com<mailto:falcon@librelist.com>" 
<falcon@librelist.com<mailto:falcon@librelist.com>>
Subject: [falcon] Sink Adapters

Hi,

Please forgive this stupid question (I’m new to API development). But what
is a ‘sink’ adapter? Can someone link me to some documentation on what 
‘sinks’ are in this context? (you try googling it! Lol)

It appears to be a method by which I can forward a request to a different 
service (web or otherwise). Basically allowing me to create a convenient 
interface layer for abstract systems – is that about right? In principle, 
a kind of reverse proxy for HTTP requests.

If so – then awesome! This is *exactly* what I have been looking for! I 
need to write a REST API that returns data that actually originates from 
an external SOAP service (among other things).

Can someone provide me with a contrived example that actually forwards 
something? The example code just returns a 503. Or is it as simple as 
using other tools to make the forward request? (such as suds, boto, etc)

Many thanks,

Geoff