d_run
2019-2-8 20:58:42

Looking at net/url and we have get\|head\|delete\|options\|post\|put-impure-port but nothing for PATCH - would it be possible to craft something similar to patch-pure-port ?



soegaard2
2019-2-8 21:03:37

d_run
2019-2-8 21:03:48

We use it in our APIs at work pretty regularly


soegaard2
2019-2-8 21:04:07

From 2010 so my guess is that net/url is older.


soegaard2
2019-2-8 21:04:25

That is, it has not been left out on purpose.


d_run
2019-2-8 21:04:29

soegaard2
2019-2-8 21:04:50

On the other hand nobody wanted it enough to make a pull request.


d_run
2019-2-8 21:04:55

oh yeah i didn’t think it was on purpose


d_run
2019-2-8 21:05:00

Okay, will work up a PR


soegaard2
2019-2-8 21:05:01

It would be natural to include it.


greg
2019-2-8 22:34:05

@d_run @soegaard2 I think when @jeapostrophe added the net/http-client module — which supports supplying any method as bytes — he hoped that would be the preferred library going forward and net/url was just for backward compatibility.



greg
2019-2-8 22:35:06

Having said that, for quick one-off things I still reach for xxx-pure-port on autopilot. It wouldn’t be horrible to round it out with a PATCH method, if you wanted to do that work.


soegaard2
2019-2-8 22:35:18

Good point.


greg
2019-2-8 22:36:33

net/http-client supports things like issuing multiple requests over one connection, with HTTP/1.1.


greg
2019-2-8 22:37:22

I would say Racket needs an HTTP/2 story, but, (a) I’m not sure it really does and (b) HTTP/3 is already on the horizon. ¯_(ツ)_/¯


d_run
2019-2-8 23:11:51

Ah I guess I’m never sure which is the preferred lib to use


d_run
2019-2-8 23:12:58

Do the methods in http-client handle redirects?


d_run
2019-2-8 23:33:53

One of the reasons I fall back on net/url is due to 302 redirects which I can’t seem to figure out how to handle with http-client


d_run
2019-2-8 23:36:07

or do I need to do that manually?


greg
2019-2-8 23:41:54

Oh that’s a good question. I don’t know.


d_run
2019-2-8 23:45:20

looks like I need to handle it based on status/headers


d_run
2019-2-8 23:45:30

which is pretty straightforward


d_run
2019-2-8 23:51:49

super janky demo

#lang racket/base

(require json
         net/head
         net/http-client
         racket/port
         racket/string)

(define (parse-headers headers)
  (for/hash ([header (map (λ (h)
                            (string-split (bytes->string/utf-8 h) ": "))
                          headers)])
    (values (car header) (cadr header))))

(define (get uri)
  (define-values (status headers body)
    (http-sendrecv "<http://httpbin.org\|httpbin.org>" uri #:method #"GET"))

  (define header-map (parse-headers headers))

  (println status)
  (displayln header-map)
  (println (port-&gt;string body))

  (when (equal? status #"HTTP/1.1 302 FOUND")
    (get (hash-ref header-map "Location"))))

(get "/absolute-redirect/4")

krismicinski
2019-2-9 01:57:15

So apologies if this is a silly question, but I’m trying to give some students of mine a “typical” #lang written in Racket. I’d like a language that is somewhat nontrivial but not as big as typed racket. Any tips on good #langs to give them? I found an EOPL language by David Van Horn that looks good, maybe that: https://github.com/racket/eopl (The downside here is—I think—that it’s using some nonstandard parser? I am not sure I get what’s going on there)


krismicinski
2019-2-9 01:57:48

this will also be a learning experience for me. I’ve only written very small #langs that build on top of #lang s-exp..


sorawee
2019-2-9 07:13:46

There’s also https://docs.racket-lang.org/plai-typed/index.html. I glanced at it and it seems to use the standard parser.


krismicinski
2019-2-9 07:21:03

whoa! This is perfect.