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
?
We use it in our APIs at work pretty regularly
From 2010 so my guess is that net/url is older.
That is, it has not been left out on purpose.
seems like in theory i could pass the method to https://github.com/racket/racket/blob/master/racket/collects/net/url.rkt#L429
On the other hand nobody wanted it enough to make a pull request.
oh yeah i didn’t think it was on purpose
Okay, will work up a PR
It would be natural to include it.
@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.
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.
Good point.
net/http-client
supports things like issuing multiple requests over one connection, with HTTP/1.1.
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. ¯_(ツ)_/¯
Ah I guess I’m never sure which is the preferred lib to use
Do the methods in http-client
handle redirects?
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
or do I need to do that manually?
Oh that’s a good question. I don’t know.
looks like I need to handle it based on status/headers
which is pretty straightforward
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->string body))
(when (equal? status #"HTTP/1.1 302 FOUND")
(get (hash-ref header-map "Location"))))
(get "/absolute-redirect/4")
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)
this will also be a learning experience for me. I’ve only written very small #langs that build on top of #lang s-exp..
There’s also https://docs.racket-lang.org/plai-typed/index.html. I glanced at it and it seems to use the standard parser.
whoa! This is perfect.