ponzu-cms / ponzu

Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.
https://docs.ponzu-cms.org
BSD 3-Clause "New" or "Revised" License
5.67k stars 387 forks source link

Support for application/json on POST? #329

Open dhilst opened 4 years ago

dhilst commented 4 years ago

There is a big note documentation quoting that Content-Type should be multipart/form-data' otherwise we get a big 400 error, is there any way to acceptapplication/json`? There are a lot of tolls that dump json, and working with json is usually easier than working with encoded form.

I understand that is not possible to upload stuff with application/json and we're talking about CMS but this is a great tool for creating API with Let's Encrypt integration would be wonderful if could accept JSON natively

Anyway, great project and the Let's Encrypt feature is a dream that came true

olliephillips commented 4 years ago

Hey @dhilst thanks for opening this. Totally agree json easier than encoded form also.
At the moment I'm not at all sure where the project stands on this, but wanted to reply and say the issue is open and noted.

dhilst commented 4 years ago

Are you willing to review PRs? I'm not fluent on go but it would be a good challenge

olliephillips commented 4 years ago

@dhilst I certainly will, but couldn't say when I'm a little rushed myself at the moment and there are a couple open that I've committed to review but haven't had the opportunity.

It might also be better to get some more input here, before digging in, just to make sure the feature is needed and won't impact anything. @nilslice is the man to input on this, but he's also quite busy ATM.

dhilst commented 4 years ago

No problem I'm usually busy too, we do at our time. I'll wait for @nilslice input :+1:

nilslice commented 4 years ago

@dhilst - thanks for the kind words, glad you're finding Ponzu useful! application/json payload support in the create/update/delete/etc API flows would be great. I don't have a ton of time these days to commit to the project though, so it would likely be a while before this lands if it's up to me to implement it :/

But, if you were interested in a PR and wanted a good place to start: https://github.com/ponzu-cms/ponzu/blob/master/system/api/create.go#L138

The system/api package has other files where that decoding happens (at least update.go, delete.go, etc). before decoding from the request's Form, switch on the Content-type header for application/json and unmarshal the JSON from the req Body into the post (the cms Content instance e.g. content.Song, content.Book, etc.)

I suppose the expected incoming JSON structure should be identical to the output in a content API response.

Before I can merge any PRs though, there is some work to get the project building on CI properly, and then converting it to support Go modules. If you're interested in helping out with those as well, it would be greatly appreciated.

olliephillips commented 4 years ago

Hi @nilslice re the CI piece and what you are thinking there - is that worth capturing in a separate issue?

Project is on CircleCI currently are you thinking of another approach diff provider or just going further with current process? I find ponzu prs quite hard to test - there are more moving parts than most projects with the repo the server and application CLI.

Anything we can do to making testing contributions through a CI process would be great. I wondered about using github actions to create a docker file that runs a built version of the submission with default project template?

Happy to try help with thoughts and some graft where possible.

On a phone - I’ll edit it later.

dhilst commented 4 years ago

Hi @nilslice I agree with @olliephillips with handling this CI stuff in another module.

I'm kind of busy too, but I think I will have some time in the next months so I can dive in this

dhilst commented 4 years ago

Well, I got something, I will organize the code and open a pull request :)

I've been testing with httpie which sends json by default

image

Foo is a simple content with string property called bar

image

The web interface shows it as pending which is the expected, right? image

BTW, nice web ui :+1:

I will submit a pull request later, so we can discuss some code ;)

Regards

dhilst commented 4 years ago

Here it is, there is some duplicated code, I'm addressing that https://github.com/ponzu-cms/ponzu/pull/335