reasonml-community / bs-express

Express bindings in Reason
MIT License
210 stars 60 forks source link

Request headers? #72

Closed adnelson closed 4 years ago

adnelson commented 4 years ago

Hi, I didn't see anything in the example file or Express.re for getting headers out of a request. I can write my own code to do it but I wanted to check if I'm missing something.

ncthbrt commented 4 years ago

@adnelson Under Request:

 /** [get return field] returns the specified HTTP request header
       field (case-insensitive match) */
  let get: (string, t) => option(string);
adnelson commented 4 years ago

Oh, ok, I was looking in the .re file as opposed to the .rei file. Thanks for the clarification! I kind of wish it were called getHeader or something as opposed to get, seeing as it would better correspond to Response.setHeader. Also I'm a little confused by the layout of the comments around these functions in Express.re:

  [@bs.send.pipe: t] [@bs.return null_undefined_to_opt]
  external get : string => option(string) = "";

  /*** [get return field] returns the specified HTTP request header
       field (case-insensitive match) */
  [@bs.get] external xhr : t => bool = "";
  /*** [xhr request] returns [true] if the request’s X-Requested-With
       header field is "XMLHttpRequest", indicating that the request was
       issued by a client library such as jQuery */

In any case, thanks again for the answer!

ncthbrt commented 4 years ago

That'd make more sense. Get is wrapping the underlying express api.

Feel free to send a PR to make the comments better.

I'm not actively contributing to this repository, but am actively triaging issues and reviewing PRs.

On Wed, 18 Dec 2019, 20:36 Allen Nelson, notifications@github.com wrote:

Oh, ok, I was looking in the .re file as opposed to the .rei file. Thanks for the clarification! I kind of wish it were called getHeader or something as opposed to get, seeing as it would better correspond to Response.setHeader. Also I'm a little confused by the layout of the comments around these functions in Express.re:

[@bs.send.pipe: t] [@bs.return null_undefined_to_opt]

external get : string => option(string) = "";

/** [get return field] returns the specified HTTP request header field (case-insensitive match) /

[@bs.get] external xhr : t => bool = "";

/** [xhr request] returns [true] if the request’s X-Requested-With header field is "XMLHttpRequest", indicating that the request was issued by a client library such as jQuery /

In any case, thanks again for the answer!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/reasonml-community/bs-express/issues/72?email_source=notifications&email_token=ACCJEWN6DDJAF2JLOOYQO53QZJUTNA5CNFSM4J4N572KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHHB7RI#issuecomment-567156677, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCJEWOEO7HMMAQ4KAIQBETQZJUTNANCNFSM4J4N572A .