
@leif If I understand what you mean, that scaling is applied internally just before calling the underlying drawing toolbox, so you don’t have to worry about it. A canvas’s event and drawing coordinates are the same.

I think the dynamic part of http://pkgs.racket-lang.org\|pkgs.racket-lang.org might be down again

Hello all. I am working on a http client for some webapi services that my company has in C#. I am running into the issue when trying to send a POST request. I have searched the web quite a bit in the last few days, and it appears
that Racket only supports sending POST requests with type form-encoded
. Even libraries such as simple-http appear to default to this as well (has code (define POST-FORM '("Content-Type: application/x-www-formurlencoded"))
). Also found a doc page that says:
1.1.1 How do I send properly formatted POST form requests?
You should send a Content-Type header with the value application/x-www-form-urlencoded and send the data formatted by net/uri-codec's form-urlencoded-encode function. For example,
(http-conn-send!
hc "/login"
#:method "POST"
#:data
(alist->form-urlencoded
(list (cons 'username "Ryu")
(cons 'password "Sheng Long")))
#:headers (list "Content-Type: application/x-www-form-urlencoded"))
Am I missing something? Our webapi endpoints use application/json as the media type.

You can certainly send whatever you want in the payload. If you want to send JSON, just use jsexpr->string
instead of list->form-urlencoded
and provide Content-Type: application/json
as a header.

I see. I tried this. Perhaps, I am doing it wrong though. The endpoint returns 415 (unsupported media type) and content type is not set when inspecting the request. My initial attempt was using the post-pure-port function. Can post some code to provide context.

Sure, some code would probably help.

Alright. I think this should be good.

(define get-site-info-url "<http://localhost:5252/rpc/System/Site/GetSiteInfo>")
(define post-body-string (string->jsexpr "{\"UID\": \"86d59b9f-1cd5-11e4-a3b3-22000b060c92\"}"))
(define post-body-bytes (jsexpr->bytes post-body-string))
(define headers (list (insert-field "Authenticate" (string-trim (build-authentication-header "POST" "/rpc/System/Site/GetSiteInfo" "OMITTED" "OMITTED") "\n\r") empty-header)
(insert-field "Content-Type" "application/json;" empty-header)))
(define polaris-port (post-pure-port (string->url get-site-info-url) post-body-bytes headers))
(define response-string (port->string polaris-port))

@joshuarowe the unfortunate tl;dr here is that sending requests to traditional http+json web services can kind of suck in racket, at least currently

@notjack Why’s that? I’ve never had an issue with that, myself.

(in my experience)

@joshuarowe I admit I had no idea net/head
existed, but it seems like the wrong thing here.

@lexi.lambda mostly lack of library support and decent structs

especially if you want decent concurrency in requests

I’ve interacted with a whole lot of JSON HTTP libraries with Racket, so… YMMV, I guess?

One script even did them concurrently using a job queue of threads and async channels.

I’m comparing to microservice frameworks and the like so admittedly my perspective is skewed

Job queue does not perform well because it doesn’t separate the connection pool from the worker pool

(where “perform well” is in high concurrency long-lived server-side contexts)

racket serving does resource isolation very well though

I will try the same thing using something other than net/head. Any suggestions to save me Google time? Seems like I could just build the headers myself too.

I would just do that.

the http package is a good foundation

everything else (including my own packages in this space) is less stable / tested and more variable in API quality

I would write (define headers (list (bytes-append #"Authenticate" (build-authentication-header ....))))
.

And then otherwise do exactly what you’re already doing.

Both are great suggestions. After I get this client working, I think I am going to gently nudge my team into possibly using Racket since it seems like I could get so much more work done with it rather than .NET.

@joshuarowe if that’s your plan I strongly recommend infecting your team’s build / deploy / operations scripts with racket

Racket is uniquely suited to that task

and people pay less attention to what languages are used for that

That is fair. We use Team city as CI/CD, so that may be possible.

If you’re using docker in your ci/cd pipeline currently (or can add that without much effort) I’ve got a few docker images for Racket

Right. I have seem an image or two. Thought it would be really nice to use in ECS or something. We are using Docker for almost every new project on my team at least.

(ECS is way easier to use as of this year’s recent re:Invent, too! …but I like to pretend I don’t know that so that people don’t try and get me to do operations work. :wink:)

@joshuarowe for future reference: https://github.com/jackfirth/racket-docker

Good stuff. Will look into it. I will update you all with when I get a change to see if those changes work too.

Well. Building the headers myself worked for sure. Not sure what is going on with that net/head lib, but am considering putting in an issue if they have a Github.

See, I thought I needed to use that lib bc inserting the newlines manually to conform to the RFC standard would have been more work, but it looks like post-pure-port handles that for you anyways.