mflatt
2017-12-22 14:05:10

@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.


notjack
2017-12-22 23:34:35

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


joshuarowe
2017-12-23 04:29:04

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.


lexi.lambda
2017-12-23 04:31:33

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.


joshuarowe
2017-12-23 04:34:44

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.


lexi.lambda
2017-12-23 04:35:26

Sure, some code would probably help.


joshuarowe
2017-12-23 04:40:25

Alright. I think this should be good.


joshuarowe
2017-12-23 04:41:17

(define get-site-info-url "<http://localhost:5252/rpc/System/Site/GetSiteInfo>") (define post-body-string (string-&gt;jsexpr "{\"UID\": \"86d59b9f-1cd5-11e4-a3b3-22000b060c92\"}")) (define post-body-bytes (jsexpr-&gt;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-&gt;url get-site-info-url) post-body-bytes headers)) (define response-string (port-&gt;string polaris-port))


notjack
2017-12-23 04:43:26

@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


lexi.lambda
2017-12-23 04:43:54

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


notjack
2017-12-23 04:43:59

(in my experience)


lexi.lambda
2017-12-23 04:44:12

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


notjack
2017-12-23 04:45:03

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


notjack
2017-12-23 04:45:59

especially if you want decent concurrency in requests


lexi.lambda
2017-12-23 04:46:21

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


lexi.lambda
2017-12-23 04:46:40

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


notjack
2017-12-23 04:46:57

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


notjack
2017-12-23 04:47:19

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


notjack
2017-12-23 04:47:57

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


notjack
2017-12-23 04:49:24

racket serving does resource isolation very well though


joshuarowe
2017-12-23 04:50:43

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.


lexi.lambda
2017-12-23 04:50:58

I would just do that.


notjack
2017-12-23 04:51:04

the http package is a good foundation


notjack
2017-12-23 04:51:48

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


lexi.lambda
2017-12-23 04:51:57

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


lexi.lambda
2017-12-23 04:52:08

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


joshuarowe
2017-12-23 04:53:05

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.


notjack
2017-12-23 04:54:03

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


notjack
2017-12-23 04:54:30

Racket is uniquely suited to that task


notjack
2017-12-23 04:54:48

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


joshuarowe
2017-12-23 04:55:15

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


notjack
2017-12-23 04:56:12

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


joshuarowe
2017-12-23 04:58:06

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.


lexi.lambda
2017-12-23 04:59:42

(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:)


notjack
2017-12-23 05:02:46

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


joshuarowe
2017-12-23 05:11:57

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


joshuarowe
2017-12-23 05:28:45

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.


joshuarowe
2017-12-23 05:30:31

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.