Testing REST API with LearnBoost’s Tobi + Vows.js

I've been looking for a clean, framework-independent way of doing white-box API testing using Node.js. For a long while, the things that popped up when doing a quick scan of the Node Package Manager package lists weren't ticking all of the right boxes: zombie.js is going for a full browser simulation but doesn't provide a simple Browser.post() method (you have to use selectors to find the form.submit button and then fire a click() on it), Node's native http.Client is too low-level and doesn't do cookies, and various other http request wrappers weren't quite cutting it either. I think I've found a solution for this particular version of the problem: LearnBoost's Tobi combined with Vows.js is letting me do clean REST API testing, with a minimum of hassle, and all the built-in sugar-coated goodness of should.js fluent assertions. For example: Future steps then include using the macros to help set up other tests that require a valid user, etc. Overall, this is the most straightforward solution I've yet found for the problem of testing a REST API while also faking a session.

Decorators In C

Turns out you can also do decorators in C, this came in handy for something else I had to work on recently. It’s not quite as nice, because functions aren’t first-class, but handy nonetheless.

Here’s what that looks like:

The output of which is:

vilimpoc@funky:~$ ./c-decorators
hello, C decorators!
functionOne: 1, 2
decorator precondition!
functionOne: 1, 2
decorator precondition!
functionTwo: 1, 2
decorator precondition!
functionThree: 1, 2
vilimpoc@funky:~$

This might be a bit simplistic, in reality, you’d probably want to decorate a function with a signature like the following, so that you can just change the structure and not bother w/a bajillion function declarations:

Again, not super elegant, but handy.

Javascript Decorators

One reason why Javascript rocks:

As a use case, imagine you want to restrict a certain set of functions to only run if you are logged in. Doing stuff like this is ridiculously easy with first-class functions.

Here’s a generic decoration example:

Update: Here’s the specific way you’d do this with node.js/Express:

Since all of the URL handlers you register have the same signature, it’s easy to add precondition checks to the handlers via decorators.

You get preconditions essentially for free, which is a damn sight better than adding the if() block to each and every handler function. Also, if you need more preconditions in the future, you can just stack them.

Repke Spaetzlerei: A Great Lunch Place

Stopped by one of my favorite spots for lunch today: Repke Spätzlerei, a cozy, cafeteria-style restaurant by Savignyplatz in Berlin.

It’s pretty busy at lunch time, as they have good deals for comfort foods like Spätzle, Schnitzel, meatloaf (Hacksteak), and Königsburger Klopse (€6,90!). The portions are a good size, but aren’t so large that they’ll put you to sleep at your next meeting. There’s always a good selection of freshly made salad sides such as: mixed bean salad, fennel and cabbage salad, or potato salad. Additionally, each of the lunch menu items usually comes with a mixed salad of some sort, with your choice of vinaigrette or yogurt dressing.

p.s. Don’t mind the crappy photos, that’s what I get for using a Motorola Milestone to take them.

Directions

Repke Spätzlerei
Bleibtreustrasse 46
10623 Berlin

Opening Hours

Daily from 11:30h