Restangular Delete with body data - angularjs

Below is my restangular delete request where i intend to pass an array of ids to delete based on user selection
var deleteIds = [1,5,10]
Restangular.all('url').customDELETE(deleteIds);
I want this deleteIds to be passed in body params. How can i send the array as body so tat i could see the request payload.

Actually I also needed to use the delete http method with data passed in the body, and I found that Restangular supports a customOperation
documentation:
https://github.com/mgonto/restangular#custom-methods
customOperation(operation, path, [params, headers, elem]): This does a custom operation to the path that we specify. This method is actually used from all the others in this subsection. Operation can be one of: get, post, put, remove, head, options, patch, trace
example:
Restangular.all('some/path/123')
.customOperation('remove', '',{'content-type': 'application/json'},[1,5,10])

Depending on the backend technology you use, the body might be ignored for DELETE requests. See this question for more info.
I would suggest you to pass the id's as a part of the url.

Related

How to apply multiple filters to a query in url for gmail api

I am using HTTP requests via an Oracle database to extract data from Gmail APIs.
In Oracle, you apply all filters to either the URL of the request or its body.
This is working fine for simple requests such as the URL below to request list of unread messages in inbox for user:
https://gmail.googleapis.com/gmail/v1/users/me/messages?maxResults=500&q=is:unread&labelIds=INBOX
If I try to add more than one filter to the URL (or LabelIds) like in the URL below, I get an error response from the request:
https://gmail.googleapis.com/gmail/v1/users/me/messages?maxResults=500&q=is:unread newer_than:2d&labelIds=INBOX
I have tried multiple iterations for "q=" part like using double quotes, but anything I try outside of 1 filter returns an error response.
The documentation at https://developers.google.com/gmail/api/guides/filtering give this filtering example, but that clearly doesn't work for me:
https://www.googleapis.com/gmail/v1/users/me/messages?q=in:sent after:2014/01/01 before:2014/02/01
I tried removing the "is:unread" filter and adding it as a label, but I get a similar issue when trying to use multiple labelIds in the URL request. Using just labelIds=INBOX works fine, but using labelIds=INBOX,UNREAD or various iterations of that with quotes and square brackets all return error responses.
How do I use multiple filters (and/or multiple labelIds) in the URL of a request?
Thanks,
Dick
It looks like the problem is with the space between each filter in the q section.
If I add %20 for the space, it works.
For example, "https://gmail.googleapis.com/gmail/v1/users/me/messages?maxResults=500&q=is:unread newer_than:2d&labelIds=INBOX" will not work, but "https://gmail.googleapis.com/gmail/v1/users/me/messages?maxResults=500&q=is:unread%20newer_than:2d&labelIds=INBOX" will work.

Use query string in URL or use multiple URL?

If I want to display many posts in my web application but every post have its own type and I want to display each type in single page so, What's the best method to do that? Is put all all posts in one url and use query string to filter the posts upon the type and display it in the page?
For example : axios.get('/posts?type =sport')
Or I have to put every single type in separate Url
For example: axios.get('/posts/sport')
Also one more question please?
use one reducer to manage every posts or create one reducer for each post type?
you can add a dynamic route to every new type.
Ex:
'/transaction' -> component-1
'/transaction/:type' -> component-any (multiple)
welcome to Stackoverflow!
I can imagine you have a web API of some sort serving a URL /posts. You want to consume that endpoint from your web application, and you are using axios to do that. I can assume you are using JSON to return that data. Correct me if I'm wrong.
Now that the basic information is "clear", what data you serve from the endpoint, and how it is requested from the client is up to you. Do you want to ask the server what types are there first, and then do one AJAX request per type? Ok. Do you want to serve all posts independent of their type? Ok. Do you want to accept POST data in your controller so you can filter the results before returning a response? Ok.
If you are looking for a more specific answer, you must give more details, or specify more. But I hope I could be of help.
Edit: complete answer.
If you want to filter the results, you have to send some additional data in your POST request, in this case, your post type. In axios, this could be done like this:
axios.post('https://example.com/posts', {
type: 'sports'
}).then((data) => {
console.log(data);
});
You can obviously get the "type" value from a select input, other variable, even the current router page. I don't know your exact setup, but you can always come back and ask ;)
THEN, in your API controller you have to get that POST parameter type, and use it to filter the results. Again, I don't know your exact setup, but for MySQL if would be a WHERE statement in your query, or similar.

Axios requests ignoring parameters

I am sending requests to the the Firebase Realtime API. When I try to delete an from item within from a specific collection (e.g. journals) and specify which journal title using axios.delete("https://topxxx-xxx.firebaseio.com/journals.json", {title: "Nature"}}) all of the journals in the collection are deleted, not just "Nature". Similarly, if I do a get request and specify a title, all journals are returned.
I have also tried using "https://topxxx-xxx.firebaseio.com/journals.json", {params: {title: "Nature"}}. but that also returns all journals. Here are an example delete request:
axios.delete("https://topxxx-xxx.firebaseio.com/journals.json", {title: this.state.title})
.catch(error=> console.log("Error" + error))
The Firebase Realtime Database API doesn't support conditional deletes. To delete a node, you must specify the entire part to that node, and (in the REST API) either use the DELETE verb or use the X-HTTP-Method-Override: DELETE header.
So the two step process:
Perform a query to find the nodes with the title you're looking for:
https://topxxx-xxx.firebaseio.com/journals.json?orderBy="title"&equalTo="the title"
Delete the matching nodes by sending a DELETE to URLs like:
https://topxxx-xxx.firebaseio.com/journals/journalId1.json
You cannot delete a specify item from a json file like that in firebase, and also using GET will return the entire collection. It is working amazingly correct from firebase side. If you want something like how you are expecting, go for a small flask server or checkout cloud functions in firebase
You probably want to send that request to a back-end services that's connected to firebase (i'm assuming since you're using axios). Then call the remove method as demonstrated here

How to keep an Array in Jmeter parameters request field

i need to add this array in the parameters in Jmeter inorder to complete the POST request. And i am getting a 400 error.
This is the array, which needs to have a POST request:
conditions :[{accountStatus: 'UNVERIFIED'}, {accountStatus: 'INVITED'}]
Just add a Parameter with blank name and put your JSON array as a value like:
You can use View Results Tree listener to inspect request and response details:
Also make sure you add HTTP Header Manager to send at least Content-Type header with the value of application/json
Add the JSON data in Body Data tab instead of parameters tab.
Another solution:
Add to the list of variables
Name - "someArray[0]"
Variable - "someText"
See more about Request options here

Thread get - just metadata

I am doing full sync this way: list of /threads and then a request to get each of the thread like /threads/{id}. However this returns me every message together with it's body data -> and I just want to fetch the metadata of the messages. I can see that in get 'messages/{id}' you can specify format but not in get threads/{id}
Threads.get() now supports format=METADATA and with that you can use the new "metadataIncludeHeaders" to further limit the headers list to a select few. This is much more efficient than using "fields" as it only fetches what is necessary from the backend rather than filtering it later on:
https://developers.google.com/gmail/api/v1/reference/users/threads/get
I assume that by metadata you mean the headers (no body). You can use the fields parameter to get just that (messages/payload/headers):
https://www.googleapis.com/gmail/v1/users/me/threads/{thread-id}?fields=messages%2Fpayload%2Fheaders&key={YOUR_API_KEY}

Resources