From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Richard Newsgroups: gmane.emacs.help Subject: Re: A (probably silly) problem with request.el Date: Sat, 06 Jun 2015 21:25:56 +0200 Message-ID: <878ubwskor.fsf@members.fsf.org> References: <87bngv89g5.fsf@mbork.pl> <87h9qmsbyn.fsf@members.fsf.org> <87fv668d9f.fsf@mbork.pl> <5571C2EC.90903@members.fsf.org> <87y4jx7so5.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1433618797 3672 80.91.229.3 (6 Jun 2015 19:26:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 6 Jun 2015 19:26:37 +0000 (UTC) Cc: Help Gnu Emacs mailing list To: Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jun 06 21:26:23 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z1JjT-0007Lx-TD for geh-help-gnu-emacs@m.gmane.org; Sat, 06 Jun 2015 21:26:16 +0200 Original-Received: from localhost ([::1]:52400 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z1JjT-0000GM-5c for geh-help-gnu-emacs@m.gmane.org; Sat, 06 Jun 2015 15:26:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46603) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z1JjE-0000DY-Vo for help-gnu-emacs@gnu.org; Sat, 06 Jun 2015 15:26:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z1JjB-0000Uz-LV for help-gnu-emacs@gnu.org; Sat, 06 Jun 2015 15:26:00 -0400 Original-Received: from mxin.ulb.ac.be ([164.15.128.112]:27922) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z1JjB-0000Up-EA for help-gnu-emacs@gnu.org; Sat, 06 Jun 2015 15:25:57 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AksKAGBIc1WkD4Xx/2dsb2JhbABbg2RZBYJQqg4BAQEBAQEGk2WGAQKBegEBAQEBAYELQQWDXQEBBHkQCAMOEyUPAQRJE4gtCNpYAQEBBwEBAQEehhmFKoUGB4QtAQSXbogZQIM6gk8wiDSHASSCCRyBVDwxgkcBAQE Original-Received: from mathsrv4.ulb.ac.be (HELO localhost) ([164.15.133.241]) by smtp.ulb.ac.be with ESMTP; 06 Jun 2015 21:25:56 +0200 In-Reply-To: <87y4jx7so5.fsf@mbork.pl> (Marcin Borkowski's message of "Fri, 05 Jun 2015 23:26:55 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 164.15.128.112 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:104799 Archived-At: Marcin Borkowski writes: > Now the question is: > how do I do anything reasonable with what I got? In my particular case > I expect json, so I'd like to use e.g. json.el to convert it to s-exps. > How do I do that? I tried > > (request "http://httpbin.org/get" :parser #'json-read), The request form will *never*[1] return json, because it returns before the request is complete. This is what asynchronous means, and that is why I said "The real job must be done by a callback function". The very first example in the homepage of the package uses httpbin.org. Here's a simplified version of it : (request "http://httpbin.org/get" :parser 'json-read :success (function* (lambda (&key data &allow-other-keys) (message "response: %S" data)))) Please try it and see what happens. The function mentionned as :success takes over once the request is complete (well, unless the request fails obviously...). That is a "callback" function. HTH, -- Nico. [1] Except in the synchronous case, e.g. (request-response-data (request "http://httpbin.org/get" :parser 'json-read :sync t)) But the doc explicitly says to not use that.