Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for application/json on POST? #329

Open
dhilst opened this issue Nov 3, 2019 · 9 comments
Open

Support for application/json on POST? #329

dhilst opened this issue Nov 3, 2019 · 9 comments

Comments

@dhilst
Copy link

dhilst commented Nov 3, 2019

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 accept application/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
Copy link
Contributor

olliephillips commented Nov 6, 2019

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
Copy link
Author

dhilst commented Nov 12, 2019

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

@olliephillips
Copy link
Contributor

@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
Copy link
Author

dhilst commented Nov 12, 2019

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

@nilslice
Copy link
Contributor

nilslice commented Nov 30, 2019

@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
Copy link
Contributor

olliephillips commented Nov 30, 2019 via email

@dhilst
Copy link
Author

dhilst commented Jan 3, 2020

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
Copy link
Author

dhilst commented Jan 15, 2020

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 👍

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

Regards

@dhilst
Copy link
Author

dhilst commented Jan 15, 2020

Here it is, there is some duplicated code, I'm addressing that
#335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants