Closed jgranduel closed 9 years ago
Hi,
You just need to remove other characters from the If-Match part, like this:
If-Match:555ed9ac84aecf8786566459
Thank you very much for your answer. It was that simple indeed! So here's the synopsis with HTTPIE along with PowerShell/Invoke-RestMethod
# CRUD DB with HTTPIE
http --auth a:a PUT <HOST>/myfirstdb desc='this is my first db'
http --auth a:a GET <HOST>/myfirstdb
http --auth a:a DELETE <HOST>/myfirstdb IF-MATCH:555ee63584aecf878656645d
# CRUD DB with PowerShell/Invoke-RestMethod
$c = Get-Credential #(a : a)
Invoke-RestMethod -Method Get -Credential $c -Uri "<HOST>/myfirstdb" -ErrorVariable err
$err.message | ConvertFrom-Json
Invoke-RestMethod -Method Put -Credential $c -Uri "<HOST>/myfirstdb" -ErrorVariable err -Body (@{ description = "Description..."} | ConvertTo-Json) -ContentType "application/json"
Invoke-RestMethod -Method Get -Credential $c -Uri "<HOST>/myfirstdb" -ErrorVariable err -OutVariable response
$etagValue = $response._etag.'$oid'
Invoke-RestMethod -Method Delete -Credential $c -Uri "<HOST>/myfirstdb" -ErrorVariable err -Headers @{ 'IF-MATCH' = $etagValue }
HTTPIE is really great with very clean responses. When response is successfull, I still don't know how to get it with PowerShell.
best regard, jgr
Hi, Do you mean you need to have the same syntax highlighting with Invoke-RestMethod as httpie? I guess you could just use httpie in place of Invoke-RestMethod in any PowersShell script, adjusting for the different syntax, of course. Unfortunately we aren't PowerShell users, but this looks like a more general question you might try to ask in places like Stackoverflow, I think. An alternative would be to create instead a Python script which uses httpie directly, I guess it shouldn't be too hard if you know a little of Python, but it depends on your use cases.
Hi,
Do you mean you need to have the same syntax highlighting with Invoke-RestMethod as httpie? no ! I was justing adding a comment in case someone is interested as it was what I was trying to use in first place. Most Rest examples out there use curl, then HTTPIE, and I mention Invoke-RestMethod. When in PowerShell on Windows, I'm trying to stick with this cmdlet (really great for autocompletion). Thanks again, ciao!
Hi,
thanks for this great project. I've been testing it following walkthrough and docs. I cannot make DELETE work with ETag. I've never used it, sorry! I did this (on Windows 7, httpie-0.9.2)
I'm sure I don't use ETag IF-MATCH correctly. I tried other syntax which return 409 Conflict as expected. Should I use $oid? Could you tell me the value I should pass around? Could an example be given with curl (as a matter of fact, with PowerShell, I use Invoke-RestMethod with a different syntax).
Thanks a lot, Best regards jgr