lus / pasty

pasty is a fast and lightweight code pasting server
https://pasty.lus.pm
MIT License
200 stars 28 forks source link

POST request to root URL #19

Open lus opened 3 years ago

lus commented 3 years ago

Maybe it would be nice to be able to create a paste by just sending a POST request to the root URL (i.e. https://pasty.lus.pm) with the request body representing the raw paste content. This endpoint should only return the raw paste ID or URL; no JSON involved. This would be nice for CLI users.

zekroTJA commented 3 years ago

Nice Idea, but why no JSON involved? I mean, you can always use jq for that stuff:

curl -Ls -X POST https://pasty.lus.pm -d @snippet.txt | jq .id

That allows users to use further information like the deletion token. But yeah, than you can also just use the /pastes endpoint in your script if you really want, I guess. ^^

lus commented 3 years ago

Yeah, I am also quite unsure about that. It would be just another endpoint to implement and we would end up with 4 different ways of creating endpoints (root URL, hastebin support, API v1 ad API v2). Maybe it's not even that reasonable.

zekroTJA commented 3 years ago

Another approach would be to use the Accept header. So if you specify application/json as Accept header value, you get a fully hydrated JSON response. Otherwise, if you do not specify any Accept header or if you pass text/plain, you simply get a Paste URL or ID like you originally supposed. Which one of these is set as default is up to you, but should not differ across the whole API in my opinion in order to maintain consistency.