Short forum post on REST API

Adam D. Ruppe destructionator at gmail.com
Sat Apr 2 08:19:04 PDT 2011


Nick Sabalausky wrote:
> A few minor typos:

Ah, the result of me being slightly lazy and changing the name of
the functions. First, I called it "someFunction", then changed
my name to the homophone "sumFunction" so it'd actually do something.

But, I did changes without proofreading afterward!


> My only concern is how much can multiply-nested calls balloon the
> query string, and can that be an issue?

I'm not sure; I just thought it up yesterday and haven't actually
used it yet.

But, I'm not too concerned. Odds are most calls would be simple;
I rarely want to do much mixing of web api calls anyway.

If it's too long for a query string, the same approach works
for POST values too - the body of a POST request is encoded the
same way as a query string, so same approach works there too.

> And what about the feasability of
> something like this: foo(bar() + 2)

I wouldn't want to build a whole language into the url, so this
would have to be offered as function. Then you simply do operator
overloading on the ApiValue struct to combine it, all lazily.

bar() -> ApiValue!int

ApiValue!int.opBinary!("+")(2) -> calls the server side sumFunction,
returning an new ApiValue, like seen in the original post.


And hah, I think D now is doing something Javascript just
can't do. We can hack through dynamic typing, but I don't think
the current version has op overloading at all.

> The only way to make *anything* clean or elegant in JS or PHP is
> to not use them at all and say you did

This is basically how I do them... that's one reason why I
was writing this. There's not really much need to access the
http apis I write through D - I can just "import mymodule;"
instead.

Exception: I write a client gui app a few weeks ago that worked
with the web server, so I used my api functions there. But, I
did it by diving into std.concurrency, so it needed a different
approach...

Now, I wonder if the get() function with callback could do it
in a different thread... probably not, the closure would be thread
local. But, passing it to some regular function pointer would
probably work.

Anyway, I'm digressing. Now though, there's some external PHP
components on external servers being added to the application,
so I've gotta make sure it's accessible from there easily enough
too.


More information about the Digitalmars-d-announce mailing list