On 05/12/2014 11:43 AM,
vladac...@gmail.com wrote:
> Hi,
>
> I am trying to create a RESTful Web service API using SWI-Prolog's
> HTTP server libraries. However, I am running into some issues related
> to implementing the URL scheme for my API. For example, I would like
> to have a list of available resources at the following URL:
>
>
http://example.com/resources
>
> This is quite straight forward and entirely feasible. On top of this,
> I would like to have access to a single resource identified by the
> unique ID "1":
>
>
http://example.com/resource/1
>
> I would like to manipulate this resource using different HTTP methods
> (GET, PUT). I had a look at the documentation for
> library(http/http_path), but I can't figure out how to define this
> type of URL and bind it to a predicate like resource(+Id).
As a server address, use
:- http_handler('/resource/', handle_resource, [prefix]).
handle_resource(Request) :-
memberchk(path_info(Resource), Request),
...
Here, Resource is an atom that gives you anything after /resource/
To generate link to a specific resource, you maye use
http_link_to_id(handle_resource, path_postfix(Resource), Link)
Cheers --- Jan
> So I guess my question is: is it possible to implement REST-like URL
> schemes in SWI-Prolog? If so, is there a particularly relevant piece
> of documentation I should be looking at?
>
> Thanks in advance, Vlad
>
> -- You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group. To unsubscribe from this group and stop
> receiving emails from it, send an email to
>
swi-prolog+...@googlegroups.com
> <mailto:
swi-prolog+...@googlegroups.com>. Visit this group at
>
http://groups.google.com/group/swi-prolog. For more options, visit
>
https://groups.google.com/d/optout.