I understand most of how a RESTful site design should function, but in implementing a blog cannot decide the best way to present the form to insert a new blog post. Would example.com/posts/create be reasonable? This feels like the "create" is not restful, like it's putting information into the URI that should be simply represented by PUT/POST.
How would others do this?
Have a look at Rails Routing for the Rails view on this.
Verb URL Controller Action Used For
GET /photos/new Photos new return an HTML form for creating a new photo
POST /photos Photos create create a new photo
So, in your situation, GET /posts/new to get the new post form, but POST /posts to create a new post.
The point is, you're POSTing a new blog post, but to do that you need to GET the form that will enable you to do this. In a way, the new blog post form is just another (static) resource.
If you don't like the way that URL feels, then change it to:
GET http://example.com/posts/createform
Use a POST to submit the information for the insert, and then have the page do a redirect to the with the new ID in the URL. You don't want to have the new information on the URL since a user refreshing the URL will post twice.
Related
I'm creating an API in Django Rest Framework and i'm thinking about best approach to provide actions like adding a post to user reading list. Firstly i've done it by GET request, because it was looking most natural and url for example looks like /api/posts/{id}/add_to_reading_list/. Now i recognized that GET should be used only to retrieve data so i've changed it to POST method and now url is looking like /api/posts/add_to_reading_list/. The first thing is that i needed to create new serializer specially to handle this action which accepts only id field, because this endpoint should accept only already created posts. Is it how it should be done? I was thinking about sending whole post object in POST method, but doesn't it a waste of bandwidth when i need only id? It will prevent me of creating a new serializer for this specific case, but i don't think that it is a correct approach.
I have been working around this problem. I have a user submitting a HTML form lets say to list their hotel on my website. I need to review this form before i add it into my hotels model to be published.
One approach i have worked on is to use a requests model where this form can be stored and later using django admin action write a custom action to add/remove the request. In case of acceptance i copy the details to my hotels model else it sends an email or a notification back to user.
Second approach is simply using django action on hotels model where the request is sent to approve it or reject it. In this case i want to know if thats possible where a data point doesn't get written to database until it's been accepted by admin. If yes how can i do that?
Finally, these details are displayed on my main page and search page for users to book these places.
If there is a better and effective way to do it. Please share that.
Thanks in advance. If something isn't clear i can answer your specific questions in the comments below 😊.
Have a nice day.
You can have is_published Boolean field in your hotel model and you can default it to false initially. After you inspect the hotel details you can set the is_published field to True from django admin.
So now whenever you are querying for hotels to show on your website. You can query
Hotel.objects.filter(is_published=True)
I would like to achieve the following:
GET all posts from a page and their related content (attachments, likes, visibility, tags, shares, comments, creation time...)
POST all that content in a new page
Assuming that I am admin of both pages.
I know that it's pretty straight forward to loop over the feed of a page and get all the posts' information. However, I'm not so sure about the POST part:
I guess that Facebook doesn't allow to "clone" people's
like/shares/comments below each post, on their behalf?
Considering that I will delete the first page, will all attachments disappear from Facebook's servers as well?
You cannot post in behalf of another user. And you cannot get all information you need with the Graph API.
What about renaming the page? If you like to delete the first page and clone it before, it looks like a rebranding or something ...
When I look at the JSON data of a post which has several photos, I see that, this is done by using attachments/subattachments.
I want to post a data with several pictures and to do this, I want to take the advantage of attachments.
When I use "object_attachment" field for the post (to page feed), it creates only one attachment. Adding several "object_attachment" fields have no effect, only the first photo is used.
I want help on how to create attachment for a post and then add this attachment to the post.
Facebook says, attachments may be added to the posts to the post by "attachment_id" field.
Thanks to eveone who helps.
I am creating a wiki in Django where users should be able to register, login, create pages and other users who also login should be able to see all created pages and then either create new pages or edit existing ones.
I have already created registration and login pages and I am fine with creating and editing content on pages. My question is - do any of you (who know Django) know how I can implement the create new pages into my site? I think it will be in a "form" form where you then specify the URL, title, and content of the new page, but how do you actually create the new pages then and be able to view all created pages to any user?
I am stuck at this wall and any help would be appreciated!
At the time of page create with the form that you mentioned, if the user is logged in, you will want to store the user ID as a foreign key in your page Model. Then when you go to display created pages for a specific user, you just follow the relationship.
This was posted a long time ago, so you will probably just want to use this Django App as it solves all of this for you, in one beautiful package:
https://github.com/benjaoming/django-wiki
Have you seen the tutorial here? http://showmedo.com/videotutorials/video?name=1100000
I built a wiki with that tutorial - I think even if it doesn't answer your question may still point you in the right direction. Hope it helps!