[racket] Calling Web Service APIs

231 views
Skip to first unread message

Jens Weber

unread,
Dec 20, 2013, 2:46:29 AM12/20/13
to racket
Hello,

Does anybody have a simple example for calling Webservices (REST) with racket?

Thanks
Jens

Norman Gray

unread,
Dec 20, 2013, 3:37:32 AM12/20/13
to Jens Weber, racket

Jens, hello.

On 2013 Dec 20, at 07:46, Jens Weber <je...@uvic.ca> wrote:

> Does anybody have a simple example for calling Webservices (REST) with racket?

I have an example of such a thing (if I'm following you correctly) at <https://bitbucket.org/nxg/audiotag> (see src/webserver/audiotag.rkt). This isn't small, but it's relatively simple in _structure_, and includes stuff to handle the GET/POST/PUT/DELETE which the REST approach is so fond of, plus extra support for things like content negotiation, and helpers for generating *ML from code.

It might also be educational in its weaknesses; this was, I think, one of my first large Racket projects, and so shouldn't be taken to be a paradigm.

In particular: If I were starting this again, I'd be a lot more strict with myself about keeping the main program (audiotag.rkt) small and componentised. I tried to do that, and have a lot of stuff in separate modules, but clearly didn't try hard enough, and the result still includes a hard-to-refactor big blob of code.

I hope it's interesting.

Best wishes,

Norman


--
Norman Gray : http://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK


____________________
Racket Users list:
http://lists.racket-lang.org/users

Greg Hendershott

unread,
Dec 20, 2013, 8:37:15 AM12/20/13
to Jens Weber, racket
On Fri, Dec 20, 2013 at 2:46 AM, Jens Weber <je...@uvic.ca> wrote:
> Does anybody have a simple example for calling Webservices (REST) with
> racket?

I got tired of the repetitive mechanics of this and made something
called webapi-markdown.

The full idea includes documentation -- that you could do a variation
of "literate programming" where the documentation for a web service
*is* the specification of it. As a web service developer you kill a
few birds with one stone: The spec, the server, and an easy way to
generate client wrappers.

However if you're a user of a web service whose developers weren't
wise enough to use this ;) you can omit the descriptive bits and just
use it as a way to generate wrapper functions.

1. https://github.com/greghendershott/webapi-markdown describes the
file format and has working examples for real services. Note that this
isn't specific to Racket.

2. wffi (web FFI) is a Racket implementation.
Repo: https://github.com/greghendershott/wffi
As a Racket package: `raco pkg install wffi`.

I've actually this to do e.g. a wrapper for the EchoNest service. The code is:
- 95% markdown:
https://github.com/greghendershott/echonest/blob/master/echonest/echonest.md
- 2% Racket: https://github.com/greghendershott/echonest/blob/master/echonest/main.rkt
- 3% misc package/project files: https://github.com/greghendershott/echonest

Although this is simple for me to use, I don't know how simple it
would be for you. Maybe there's an opportunity to make something in
the same spirit, but even simpler. Like, a function that you give the
request template and a dictionary of your values.
Reply all
Reply to author
Forward
0 new messages