What have you found for these years?

2011-04-12

POST request for FQL in rest-graph

This cost me almost a whole day to complete... I felt somehow
mind twisted doing this. And rest-graph is no longer simple in
terms of source code, this makes me feel sad. But, that's life,
I guess.

*

Ok, this might be a big change to allow FQL to use POST instead. see:

In Graph API, it is not a big issue to use GET for querying data,
because the interface is pretty simple and straightforward. But this
is not true while using FQL. FQL query could be very long and complex.
It would be even worse using Multi-FQL. Long URI introduces problems,
including but not limiting to URI parsing issue[0], it would be good
to eliminate the problem from the beginning.

Since Facebook accepts POST against FQL queries, the easiest way to
workaround this is simply change GET requests to POST requests.
However, this is not really as simple as it seems in rest-graph.
rest-graph has cache support for all GET requests, indexed with its
requesting URI. Simply change GET to POST has two problems:

1. This special POST request should be cached as well.
2. The caching key should not only be the requesting URI, but also
contain the POST payload!

So, it's better to make it a POST underneath, but considered a GET.
That way, the cache would work for both real GET or faked GET. (POST)

We introduce `RestGraph.new.fql('fql query', {}, :post => true)`
That is, the additional :post => true option to make it a faked GET.
This works for all old_rest related API, but not for Graph API,
which you would use like `RestGraph.new.get('me')`, it doe not really
make sense to use `get` while passing `post`, and in a *REAL* REST API,
GET and POST have semantics difference, they should not be mixed
together.

Also, errors should not be cached at all, preventing from Facebook
returning a temporary error you should try again later.

[0] Since Ruby 1.8 uses a very complex regular expression to parse it,
a very long URI sometimes would cause it raising SystemStackError
(stack overflow). Though Ruby 1.9 has a better regexp engine, I am not
sure if it won't be suffering from this issue.

POST request for FQL in rest-graph

0 retries:

Post a Comment

Note: Only a member of this blog may post a comment.



All texts are licensed under CC Attribution 3.0