Im constructing a URL from query items using URLComponents and I want to add some query items as OR conditions rather than AND. Im not sure what the proper terminology for this is. Anyway I would like the following, roughly
website.com/things?param1=thing¶m2=thing|param3=thing|param4=thing
but appending query items i can only get
website.com/things?param1=thing¶m2=thing¶m3=thing¶m4=thing
My goal is to check 3 different parameters for the term I pass in, and return any results that match from any of the 3. If I was constructing the url from a string, I could just use a pipe instead of ampersand (I think - please correct me if wrong), but Im using URLComponents and am not sure how to do this.
Perhaps Im going about this incorrectly. I dont have a ton of experience with this. If this is the wrong approach, please point me in the right direction. Im not sure how to word this question appropriately and that makes it hard to search for an answer
Im not sure what the proper terminology for this is
There is no terminology for it; it doesn't exist. What you're trying to do is nonstandard. There is no such thing as a query item OR condition. Standard separators are semicolon and ampersand, with ampersand used almost universally. You can't use a pipe to separate query items.
Thus, for example, if you paste website.com/things?param1=thing¶m2=thing|param3=thing|param4=thing into the parser at http://www.freeformatter.com/url-parser-query-string-splitter.html, it doesn't know what to make of the pipes; it thinks that param2 must be thing|param3=thing|param4=thing.
Thus, URLComponents is not going to insert the pipe for you. Its goal and purpose is to make a valid URL, and you are attempting to make an invalid one.
Related
As the document says, MediaResponse contains mediaObjects property, and mediaObjects is array of mediaObject, but when I tried to put multiple mediaObjects, I got this error:
MalformedResponse at
expected_inputs[0].input_prompt.rich_initial_prompt.items1.media_response:
Only 1 media_object is allowed. First media_object will be used while
rest will be filtered.
Then what is the point of having an array of mediaObject?
There are several places in the protocol that contain an array where only one object is permitted in the array. One assumes that the designers wanted to make it expandable in the future without having to add special casing.
In this case, it sorta makes sense - right now we can only send one media object as part of the reply. It might be reasonable that, in the future, we could send one or more without having to come back to our webhook.
I want to compare a url to a specific path to see if they match. I have tried so many variations and just can't get it to work, the two items I need to use are
{%CurrentDocument.RelativeURL.Replace("~","")%}
and
{&/{0}/{1}/{2}|(tolower)&}
In the current test scenario, both of these return the same string, however, when I put them together
{%CurrentDocument.RelativeURL.Replace("~","")|(equals){&/{0}/{1}/{2}|(tolower)&}|(truevalue)yes#%}
I get a false result displaying, I'm pretty positive it's because I can't nest a path expression inside an expression but not sure if there is another way? Any help would be appreciated.
Thanks
According to the documentation you should be able to substitute path macro with {%Path.path%}. Then there is no need to nest different types of macros but use the Path the same way as CurrentDocument.
We have REST API's. I was trying to figure out the best way to do a Get with some special characters.
Currently, we have something like this: http://myhost.com/api/book/name=HarryPotter
The above URL works just fine, but gets complicated when certain special character's are included in the queryparam like '&' or '/', which will result in "No operation matching request path ... is found, HTTP Method : GET, ContentType : /, Accept : /,"
for ex: http://myhost.com/api/book/name=Dark/Thirty.
This will consider the '/' in 'Dark/Thirty' as an URL separator.
What is the best practice to be able to search such queries. Is using a JSON a better practice, if yes should I be using a GET or a POST? I believe it should be POST, as any slash in the query param is treated as an Url separator.
Meaning: even this would fail for GET. http://myhost.com/api/book/search={"name"="Dark/Thirty"}
And since this is actually not a POST i do not want to use it. As I am just listing out the books that meet my search criteria and not modifying or adding anything.
Any guideline in tackling similar problems?
This link is a good read. In essence, if your Dark/Thirty is an identifier (i.e. uniquely identifies a resource), then modify it (in a predictable pattern) so that it does not have the special characters; e.g., DarkThirty or dark-thirty. If it is, however, a search term, then you would be better served not to make it RESTful, but just pass it as a normal parameter; that's what they're for.
The difference between GET and POST is not what characters are in it, but what the objective is. GET is for getting stuff: it should be free of side effects. A search, or retrieval of a page should be a GET. POST effects changes to a server. It is improbable you would need to make an operation that both requires sending more data than URL allows, and at the same time makes no changes on the server but simply renders a new page (allowing for exceptions like Shazam or TinEye).
Dealing with special characters in GET parameters is the job of URL encoding; if you have http://myhost.com/api/search?q=Dark%FThirty for a search, your site is no less good. There are two primary drivers for REST, as I understand them: human-friendliness and SEO-friendliness. Search does not need to be either. REST exists to identify resources, in my understanding; and search results from a query are not a resource.
To summarise, I'd go with:
http://myhost.com/api/book/dark-thirty (the resource is the book)
http://myhost.com/api/search?q=Dark%FThirty (the resource is the search procedure, with arguments)
URL encoding sounds like the easiest thing to do in your case, particularly since you already have a URL structure set up for your application that looks like http://myhost.com/api/book/name={internal-identifier} where internal-identifier resolves to your book name (encoded, of course).
From the REST perspective, it doesn't particularly matter whether the URL represents a query that can return a collection of resource representations or uniquely identifies a specific resource. You can use this structure for both.
What we want is basically this:
/foo/* controllers.FooController.foo
However this doesn't work.
We have found the following workaround:
/foo/*ignore controllers.FooController.foo(ignore)
But this makes the code of the method controllers.FooController.foo slightly ugly. Is there a better way to do this?
Looking at the code over here, the router isn't able to deal with the "slug" part without specifying an identifier... the parser combinator doesn't declare it as optional, and the map (^^) is clearly using it as is.
It could be a good feature request if it wouldn't induce other problems where a pattern will hide all other routes because it's defined higher in the file (or even worst, included).
And it looks like it has been done on purpose if we look here, we can figure out that dynamic parameter cannot be assigned a default value -- indeed, in this case we'll fall in the case I've just mentioned :-/.
My first advice would be to tell you to use ignore as an Option[String] and the action definition to set it as None (rather than an empty String because it's more expressive).
My second would be to incite you to wonder if such case is really relevant, because it's error prone and could hide further problems
Is there any way to get the indices of the same string (that appears more than once) in a single array? I know I can find a specific string's location using:
[nameOfArray indexOfObject:#"apple"]
Of course, I could create a for loop essentially using the same code above and ignoring the previous "apples" found. I can't help to feel that there is a simpler (built-in) way to do this in objective-c. Am I right?
Thank you all in advance.
You could use indexesOfObjectsPassingTest with the "test" block being a block that tests for equality.