I’ll admit it: I have previously tried and failed to get the new HTTP REST client in JetBrains PhpStorm to do what I wanted, especially with POST requests and file uploads. This morning, the stars aligned properly and my magic beans sprouted and life is beautiful.
Here is the code. It does a POST call with three form fields, api_key, max_to_ban, and testing. It also has a file upload field. The filename presented to the server is “customers.csv”. The contents of the file on my workstation are read from /home/azemon/Desktop/customers.csv.
POST http://localhost:8080/import/import_users Accept: application/json Cache-Control: no-cache Content-Type: multipart/form-data; boundary=WebAppBoundary --WebAppBoundary Content-Disposition: form-data; name="api_key" Content-Type: text/plain kzce06oenUoTYorFQ7fEXA** --WebAppBoundary Content-Disposition: form-data; name="max_to_ban" Content-Type: text/plain 0 --WebAppBoundary Content-Disposition: form-data; name="testing" Content-Type: text/plain 1 --WebAppBoundary Content-Disposition: form-data; name="file"; filename="customers.csv" Content-Type: text/plain < /home/azemon/Desktop/customers.csv --WebAppBoundary-- ###
It is kind of verbose, so typing it all the first time was tedious. On the other hand, changes are trivial because it is just text and easy for me to edit. When I run this, PhpStorm pops open the Run pane and I see this:
POST http://localhost:8080/import/import_users HTTP/1.1 200 OK Date: Fri, 21 Sep 2018 17:38:46 GMT Server: Apache/2.4.34 (Ubuntu) Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin Content-Security-Policy: default-src 'self'; connect-src 'self' https://www.google-analytics.com; script-src 'self' www.google-analytics.com 'unsafe-inline' 'unsafe-eval'; style-src 'self' https://fonts.googleapis.com 'unsafe-inline'; frame-src 'self' www.youtube.com; img-src * data: blob: filesystem:; media-src *; font-src 'self' https://fonts.gstatic.com; Vary: Origin Access-Control-Allow-Headers: <snip> Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: application/json { "error": "<snip>", "code": 500, "success": 0 } Response code: 200 (OK); Time: 1205ms; Content length: 82 bytes
Ed Greenberg says
I’ve been using Postman. My main objection to it is that it takes up a bunch of resources, since it’s written in node (javascript.) I like that it saves every one of my transactions so I can go back, pull one up, modify it and run it again.