Best REST client with a query builder?

342 views
Skip to first unread message

Paul

unread,
Aug 1, 2014, 3:37:36 PM8/1/14
to nod...@googlegroups.com
So i've been looking for a REST client that lets you specify path parameters the same way that express handles routes with params in them.

I've been superagent for most of my http needs, but I want something that goes one step further and automatically handles the encoding/replacing of parameters.

Ideally I'd be able to do something like this with a request builder:

var path = "/users/:userId/things/:thingName/:optionalParam?";
var params = { userId: 1, thingName: "My Super Thing & Stuff"; }
var query = { search: "my search", type: 1 };

rest
.get()
   
.base('http://api.example.com')
   
.path(path, params)
    .query(query)
   
.accept('json')
   
.end(function() {}); // actually execute the request


This would execute a request to:

http://api.example.com/users/1/things/My%20Super%20Thing%20%26%20Stuff?query=my%20search&type=1

What do people use for calling REST apis, besides manually constructing the URL by concatenating/encoding things?

I'd expect something like this to exist already, so before I make it I wanted to check with the community.

Levi Lewis

unread,
Aug 2, 2014, 2:30:06 PM8/2/14
to nod...@googlegroups.com
The Swagger JS client can do it, but may take this a bit further than what you are asking for. Requires your API to expose swagger spec compliant JSON to describe the web services.

 Document API with this:

Then point the js client to API

Bonus, after those two steps:

In addition to js, generate other clients:

-- Levi
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/a1db38d0-6c20-4758-a072-b514f83b663c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul

unread,
Aug 4, 2014, 11:36:05 AM8/4/14
to nod...@googlegroups.com
Thanks for the links. Swagger looks interesting but it is definitely a bit overkill for what I'm looking for. I was thinking of something more generic that just closes the gap between superagent and manual uri building.
Reply all
Reply to author
Forward
0 new messages