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.68k stars 387 forks source link

Retrieve Types list via API #282

Closed ejemba closed 5 years ago

ejemba commented 5 years ago

Hello thank you for ponzu !

I was looking for a way to get existing types from ponzu via the api (andclient), and can not figure out if this is possible in the current version.

I have a use case where I need the list of types .

Thank you !

nilslice commented 5 years ago

Hi @ejemba -

I'm glad you are enjoying Ponzu! I saw your other issue, and will reply asap, but I am travelling and don't have enough time to give it a thoughtful enough response yet.

To try and quickly address this issue: Fetching the list of types can be done by adding a route to call a handler, which I intentionally unimplemented a long time ago for security reasons. In any of your content types, you can add handlers to the default http serve mux, used by Ponzu globally. I'd try to offer more code to demonstrate the implementation, but I'm short on time. See the handler func below, as it should give you a good starting point:

https://github.com/ponzu-cms/ponzu/blob/6efa91347dc7e43e61f48d459925b81ae933732e/system/api/handlers.go#L18-L34

Feel free to update this issue with additional comments if you have problems or questions and I will help out asap.

ejemba commented 5 years ago

Hi @nilslice thank you for your quick feedback :) I think this is my first issue here :) so do not worry I just need types list for now.

I'll check your solution out this evening and I keep you informed.

Otherwise, don't you think types can be a valid update in your current API. I mean without hack Thank you

nilslice commented 5 years ago

Oops, you are right - the other issue is by a similar username - sorry about that!

The reason I removed this endpoint from the list if defaults was so that there was no way to scan the Internet for Ponzu APIs, quickly get all the types and iterate through them calling the content endpoints and download all of your CMS's data. Also, many times various types contain sensitive data that could be dangerous to expose by default.

olliephillips commented 5 years ago

Closing this issue. It appears to be answered/resolved. Please reopen if not the case.