* [Caml-list] ocamlnet question: get with arbitrary header
@ 2018-03-21 19:29 Alan Schmitt
2018-03-22 19:55 ` Gerd Stolpmann
0 siblings, 1 reply; 4+ messages in thread
From: Alan Schmitt @ 2018-03-21 19:29 UTC (permalink / raw)
To: OCaml Mailing List
[-- Attachment #1: Type: text/plain, Size: 608 bytes --]
Hello,
I'm writing a small tool to fetch articles from wallabag, and as part of
the protocol I first need to get a token, then in subsequent calls I
need to provide it as a http header. I've been using
Nethttp_client.Convenience till now, but I don't see a way to specify an
http header. I looked at the documentation for Nethttp_client, and I'm
not seeing it either. Is there a way to set a header for a GET request
to Authorization with value Bearer foobar?
Thanks,
Alan
--
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂, Mauna Loa Obs. 2018-02: 408.35, 2017-02: 406.42
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 528 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] ocamlnet question: get with arbitrary header
2018-03-21 19:29 [Caml-list] ocamlnet question: get with arbitrary header Alan Schmitt
@ 2018-03-22 19:55 ` Gerd Stolpmann
2018-03-26 5:57 ` Alan Schmitt
0 siblings, 1 reply; 4+ messages in thread
From: Gerd Stolpmann @ 2018-03-22 19:55 UTC (permalink / raw)
To: Alan Schmitt, OCaml Mailing List
[-- Attachment #1.1: Type: text/plain, Size: 1341 bytes --]
No, with the Convenience module you cannot do it. It's really meant for
super-simple stuff only.
But you can do:
let pipeline = new Nethttp.pipeline in
let call = new Nethttp_client.get url in
call # set_request_header (new Netmime.basic_mime_header
["Authorization", ...]);
pipeline # add call;
pipeline # run()
then check for call # response_* values. You can reuse the pipeline
across calls.
Gerd
On 21.03.18 20:29, Alan Schmitt wrote:
> Hello,
>
> I'm writing a small tool to fetch articles from wallabag, and as part of
> the protocol I first need to get a token, then in subsequent calls I
> need to provide it as a http header. I've been using
> Nethttp_client.Convenience till now, but I don't see a way to specify an
> http header. I looked at the documentation for Nethttp_client, and I'm
> not seeing it either. Is there a way to set a header for a GET request
> to Authorization with value Bearer foobar?
>
> Thanks,
>
> Alan
>
--
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de
My OCaml site: http://www.camlcity.org
Contact details: http://www.camlcity.org/contact.html
Company homepage: http://www.gerd-stolpmann.de
------------------------------------------------------------
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] ocamlnet question: get with arbitrary header
2018-03-22 19:55 ` Gerd Stolpmann
@ 2018-03-26 5:57 ` Alan Schmitt
2018-03-26 12:04 ` Gerd Stolpmann
0 siblings, 1 reply; 4+ messages in thread
From: Alan Schmitt @ 2018-03-26 5:57 UTC (permalink / raw)
To: Gerd Stolpmann; +Cc: OCaml Mailing List
[-- Attachment #1: Type: text/plain, Size: 781 bytes --]
Hello Gerd,
On 2018-03-22 20:55, Gerd Stolpmann <info@gerd-stolpmann.de> writes:
> No, with the Convenience module you cannot do it. It's really meant for
> super-simple stuff only.
>
> But you can do:
>
> let pipeline = new Nethttp.pipeline in
> let call = new Nethttp_client.get url in
> call # set_request_header (new Netmime.basic_mime_header
> ["Authorization", ...]);
> pipeline # add call;
> pipeline # run()
>
> then check for call # response_* values. You can reuse the pipeline
> across calls.
Thank you for the tip. The API I'm interacting with also uses the PATCH
method, is there support for it in ocamlnet?
Best,
Alan
--
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂, Mauna Loa Obs. 2018-02: 408.35, 2017-02: 406.42
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 528 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] ocamlnet question: get with arbitrary header
2018-03-26 5:57 ` Alan Schmitt
@ 2018-03-26 12:04 ` Gerd Stolpmann
0 siblings, 0 replies; 4+ messages in thread
From: Gerd Stolpmann @ 2018-03-26 12:04 UTC (permalink / raw)
To: Alan Schmitt, Gerd Stolpmann; +Cc: OCaml Mailing List
[-- Attachment #1.1: Type: text/plain, Size: 1773 bytes --]
On 26.03.18 07:57, Alan Schmitt wrote:
> Hello Gerd,
>
> On 2018-03-22 20:55, Gerd Stolpmann <info@gerd-stolpmann.de> writes:
>
>> No, with the Convenience module you cannot do it. It's really meant for
>> super-simple stuff only.
>>
>> But you can do:
>>
>> let pipeline = new Nethttp.pipeline in
>> let call = new Nethttp_client.get url in
>> call # set_request_header (new Netmime.basic_mime_header
>> ["Authorization", ...]);
>> pipeline # add call;
>> pipeline # run()
>>
>> then check for call # response_* values. You can reuse the pipeline
>> across calls.
> Thank you for the tip. The API I'm interacting with also uses the PATCH
> method, is there support for it in ocamlnet?
Well, you would have to create your own class for that, e.g. there is
for GET:
class get_call = object(self) inherit generic_call method private
fixup_request() = () method private def_request_method = "GET"
method private def_is_idempotent = true method private
def_has_req_body = false method private def_has_resp_body = true
method private def_empty_path_replacement = "/" end
class get the_query = object (self) inherit get_call
initializer self # set_request_uri the_query end
For PATCH you'd have to define something along these lines. For other
examples like POST see the source code.
Gerd
> Best,
>
> Alan
>
--
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de
My OCaml site: http://www.camlcity.org
Contact details: http://www.camlcity.org/contact.html
Company homepage: http://www.gerd-stolpmann.de
------------------------------------------------------------
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-03-26 12:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-21 19:29 [Caml-list] ocamlnet question: get with arbitrary header Alan Schmitt
2018-03-22 19:55 ` Gerd Stolpmann
2018-03-26 5:57 ` Alan Schmitt
2018-03-26 12:04 ` Gerd Stolpmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox