How to post data to ember route without showing in url? - ember.js

Need to post data/datas to ember route without showing in url ,
Optional parameters to route

As long as you don't specify the property as a query parameter you should be able to pass anything to the route and then on as a request without it showing in the Ember URL.

Related

How to get the page ID from a public notion page url without querying a database

I would like to be able to receive a public Notion page URL and return the ID of that page. I don't know if that is possible using the API.
I've tried taking the end of this URL and using it to retrieve the page in postman
https://www.notion.so/asnunes/Simple-Page-Text-4d64bbc0634d4758befa85c5a3a6c22f
https://api.notion.com/v1/pages/4d64bbc0634d4758befa85c5a3a6c22f
But it didn't work :/
The ID of the page is that alphanumeric string at the end of the URL before the query parameters. This would be what you would use when retrieving information from the page using the GET Page or GET block endpoints in the API.
If you do not have access to the page (i.e. your integration does not have access to the page in your workspace) you will not be able to use the API to make a request to it. You cannot use integrations to request information from other workspaces. Your integration is not authorized to access other workspaces.

Why use URL parameters over request body in API?

When making an API endpoint in Django Rest Framework for example, why would I ever use URL parameters to receive data rather than just putting everything in the request data?
I don't get the difference between the two.
Putting some query data in the URL allows the URL to store the "state" of your web application.
For example a state can be "I queried how do I make cheese on stackoverflow", and the URL would be https://stackoverflow.com/search?q=how+do+make+cheese.
This allows the web app to interact as expected with browser tools like Refresh, Go Back, etc. Without the state stored in the URL, refreshing the page might just take you back to the homepage, instead of showing you the same query results (the expected behaviour).
Additionally, you can copy & paste the URL. When someone clicks on it, they will be taken directly to that specific state.
On the other hand, you shouldn't use the URL to store/send sensitive data (as it can easily be seen, use the body instead), and you should make sure reloading an "action" URL won't execute the action again (like paying for a product twice!).
The URL parameters and body parameters server different purpose. The REST API grammar says
GET Method is used when you want to retrieve data back and don't want to update any of the record in system. The GET method will not pass body parameter and hence whatever filter parameters passed to API will be through URL parameters.
POST/PUT Method is used whenever you want to update your database. The value could be single parameter or even no input but you have to use POST/PUT method, if you are trying to update database record(s).

Ember and custom endpoint

I have a problem with ember in a custom endpoint and a component
I need to get data from the custom endpoint when using a simple findAll the component works perfect but the findAll not going to custom endpoint, When I use adapter ajax goes to the custom endpoint and then pushPayload the data to the store but the component does not work.
What is the best way to call to an custom endpoint from Ember?

View design for a Django website which has a RESTful API from the get go

I am trying to build a Django powered website. I want the website to be dynamic. For example, I want the profile page for a authenticated user to contain multiple resources (like a friends list, a group list, usage history etc) and these resources should be loaded in the same area on the page by making API calls without reloading the page.
Here is my understanding of the process:
Browser on the client side requests the profile page at www.example.com/user:id
The server returns a HTTP response and sends the html, css and javascript to the browser.
To load variable resources on the webpage, for example, the friend list, the javascript makes API calls using HTTP and sending context in JSON.
The API returns a JSON response which contain the data requested.
Javascript renders the data as html and the client is able to see new content on the same page.
I thought that in order to do this, some of my server side views need to be ordinary Django views which returns an HTTP response, while some others need to be API views which return JSON.
Now here's my confusion. Let's say www.example.com/user:id is processed using an ordinary django view, while www.example.com/user/:id/friendslist is processed using an API view. Now if the user inadvertently points the browser at www.example.com/user/:id/friendslist by typing the entire URL and hits go, what happens?
If I go with the flow of logic that I mentioned above, then the view will simply return a JSON. No html, css or javascript. In this case, how will the browser know what html to display?
I am just a beginner and I am sure I got the flow of logic wrong. Can someone please point out which part I got wrong?
Now if the user inadvertently points the browser at www.example.com/user/:id/friendslist by typing the entire URL and hits go, what happens?
It depends on how you coded your server. In Django you can use is_ajax to check whether the request was AJAX or not. You could return an HTTP error code when the request is not an AJAX one, if you wanted. So a user who inadvertently points the browser to your URL but does not take any further action will get an error.
Note here that a knowledgeable user could circumvent is_ajax by setting the request header field HTTP_X_REQUESTED_WITH to XMLHttpRequest manually.
If I go with the flow of logic that I mentioned above, then the view will simply return a JSON. No html, css or javascript. In this case, how will the browser know what html to display?
Setting your returned data type to application/json already tells the browser what it is dealing with. The least a browser would do this with this is display it as text.
Here's an example of an API call that returns JSON: https://api.zotero.org/users/475425/collections/9KH9TNSJ/items?format=json My browser just shows the JSON.

Server to ask Ember app to display one of its route while passing model data

My understanding is that if a given route in an Ember app needs to grab data from the server to feed its model, we will either use Ember data with a RESTful API or just an AJAX request, and the request for model data will come from the Ember app to the server.
But what if I want the server itself, at the end of a server-side process, to ask the Ember app to display one of its routes by passing to it some data to be used as the route model?
Basically, a process on the Node-based server (with Express) ends up like so:
function(req,res) {
res.redirect("/#/someEmberAppRoute");
}
The req parameter carries some object that I want to pass to the Ember route in order to be used as a model for that route.
The way I ended up solving this problem was to store on the server the output of the server-side process and have the Ember route someEmberAppRoute's model send a GET request to the server to grab that output and feed its model, instead of trying to push it directly from the server to the client.