What is the difference between 'path' and 'query' in a API call - javascript

I m trying to implement faceit API in my website.There are two end points from which I can retieve a player's information
1.https://open.faceit.com/data/v4/players?nickname=DeADLY2501&game=CSGO&game_player_id=76561198806878477
This is the first way.Below i will link a image.From faceit documentation(https://developers.faceit.com/docs/tools/data-api)
Here there is a parameter called 'game_player_id' which says it must be a string and 'query'.
Here is the second endpoint
Here in which a parameter is need called 'player_id' which is required needs to be a string and must be a 'path'.
Can some one please tell me what is the difference.Because in the first end point.We need 'nickname','game' and 'game_player_id'.
I just want to retrive a players information just from the id,So that can be made possible by the second endpoint.The problem is that.With the same 'player_id',I send calls for both end points.The first one sends a response successfuly.While the second endpoint says 'Not Found'.I gather that it might be that the type of parameter im making the request with are not proper for the 2nd endpoint.
Any help regarding this is appriciated thank you.

There is a formal definition here
But sometimes it's easier to see an example, consider https://stackoverflow.com/questions/62362966/?arg=3;other=word This is composed of several parts:
https - this is the scheme
stackoverflow.com - this is the hostname
questions/62362966/ - this is the path
arg=3;other=word - this is the query
Note that where your documentation above refers to a value appearing in a path or query, that does not mean it exclusively constitutes the path or query - there is also data/meta-data framing it.

Path and query - different parts of the URL. Basically, everything that goes after ? is query, everything between domain and ? is path.
See details here

In example below I mean the user_id is a path.
https://www.example.com/api/v2/users/{user_id}
https://www.example.com/api/v2/users/11
In example below I mean the limit and the page is a query.
https://www.example.com/api/v2/users?limit={limit_value}&page={limit_value}
https://www.example.com/api/v2/users?limit=50&page=1

A query goes after ? AND is made up of a key and a value in the form key=value. Each pair is separeted by a &.
A path is what goes after the first slash (/) and before ?. It doesn't require the key-value pattern. You just put the value in the right spot (i.e. between other slashes).

Related

How to code one (RESTful) route with more than one parameter

My node server uses one and only one route: GET /I/want/title
This route expects a list of websites addresses in query string format e.g.
/web/=http://bing.com
/web/?address=http://yahoo.com
This works ok, so how to use one route for both or more?
yahoo&bing
Only one route will be used for both single and multiple requests.
You could use, for example:
/I/want/title/?address=bing.com,www.yahoo.com
And then easily split parameter to array:
var addressesArray = address.split(',');

Angular translate provider - Is there a way to replace general variables?

In my app, many of my translation string need to include the user name in them.
For example: Hello {{user_name}}!
(User name has to be part of the translation string since the position of the name in the string depends on the language))
The way to set attributes is {{"TRANSLATE_ID" | translate:{user_name:myUserName}}}
Since {{user_name}} appears in more than 100 translation strings, I don't want to send the user_name parameter so many times. I'd like to have a way to set this parameter only one.
I can't replace the {{user_name}} string in the config because the user_name is set asynchronously (fetched from the server) and isn't available when translateProvider sets the strings.
Thanks
AngularTranslate allows you to translate tags from the html itself or inside the controller through a promise. I believe the elegant way to do what you want is to create a method/function in your controller that handles the translation in the way you want and then call this method/function in your html passing the username as a parameter.
Address the username in your JSON translation files as "USERNAME" for instance, such as "Hello, USERNAME!", do the translation in a method created in your controller using AngularTranslate and then do a string replacement changing the word USERNAME for the method parameter (the real username) and use this string as the method's return value, which will be called in your html.
Hope this helps.

Issue with picking multiple JSON

I have recorded a script and "search" an id from it.
I have performed the following things
Have parametrize the "searcID" so that it can be picked from the "CSV_Data Config"
Have extracted the "key" from the URL through "Regular Expression Extractor" to provide it to the desired URL requiring "key", so that it can be dynamic
Now the issue is, since the script is recorded for one search id, in "/build-4.4.10.0/SECChecker/Search/Html?_dc=0.5557150364018139&Grid-Ajax", the last line of my script has a body of the one recorded "searchId".
The script runs and return for each thread this same result of JSON (that is present in the last line i mentioned), i want this too to be dynamic, how can i do that? Please guide
If you want to parametrize the last request, you should use the following notation: ${"var name"} and use a CSV manager. link2
for instance, if you want to parametrize the fist param of the body you should have something like this:
{"SortField":"${var_name}",....
One thing, the dc param, part of the path, looks like a random used to avoid cache, so I use this to simulate the requests during the test:
.../Html?_dc=${__RandomString(15,0123456789)}&Grid-Ajax
This function returns a string which its length is 15 (1st param) and has a set of numbers (2nd param)
Hope It helps you.

Auto Complete does not filter results when I'm typing

I have very simple form that gets values in JSON format from searchAlbum.php. It works when I start typing something in, but it does not filter results, for example it shows 123 as available even though I typed ab.
This is what my saerchAlbum.php is returning
["123","abc"]
This is my Java Script code
$(document).ready(function(){
$('.albumName').autocomplete({
source: 'searchAlbum.php'
});
});
You might say that it should not filter my resoulds and I need to pass my input as a paramater but why then this examle on jquery-ui page does that for me?
The documentation isn't clear about it, but the only time the autocompleter does the filtering for you is when your code isn't getting called at all (e.g., you've given it an array as source). When your code is getting called (either client-side code because you've given a function for source, or server-side code because you've given a URL), your code is expected to do the filtering.
You might say that it should not filter my resoulds and I need to pass my input as a paramater but why then this examle on jquery-ui page does that for me?
Because the search.php page that the example calls filters the results based on the term parameter the autocompleter passes it. Compare the results you get from these:
http://jqueryui.com/demos/autocomplete/search.php?term=ti
http://jqueryui.com/demos/autocomplete/search.php?term=ro
You can see that it's filtering server-side.
The js sends a query string parameter named "term", your php code needs to return data by filtering existing data that match the "term" parameter.
This isn't a Javascript or jQuery problem, but a PHP problem. As mentioned in the linked jQuery-UI page, the source script must process the "term" property via a GET request.

How Do You Fix A Parameter Names Mismatch - DOJO and PL/SQL

How do you fix a names mismatch problem, if the client-side names are keywords or reserved words in the server-side language you are using?
The DOJO JavaScript toolkit has a QueryReadStore class that you can subclass to submit REST patterned queries to the server. I'm using this in conjunction w/ the FilteringSelect Dijit.
I can subclass the QueryReadStore and specify the parameters and arguments getting passed to the server. But somewhere along the way, a "start" and "count" parameter are being passed from the client to the server. I went into the API and discovered that the QueryReadStore.js is sending those parameter names.
I'm using Fiddler to confirm what's actually being sent and brought back. The server response is telling me I have a parameter names mismatch, because of the "start" and "count" parameters. The problem is, I can't use "start" and "count" in PL/SQL.
Workaround or correct implementation advice would be appreciated...thx.
//I tried putting the code snippet in here, but since it's largely HTML, that didn't work so well.
While it feels like the wrong thing to do, because I'm hacking at a well tested, nicely written JavaScript toolkit, this is how I fixed the problem:
I went into the DOJOX QueryReadStore.js and replaced the "start" and "count" references with acceptable (to the server-side language) parameter names.
I would have like to handled the issue via my PL/SQL (but I don't know how to get around reserved words) or client-side code (subclassing did not do the trick)...without getting into the internals of the library. But it works, and I can move on.
As opposed to removing it from the API, as you mentioned, you can actually create a subclass with your own fetch, and remove start/count parameters (theoretically). Have a look at this URL for guidance:
http://www.sitepen.com/blog/2008/06/25/web-service-data-store/
Start and count are actually very useful because they allow you to pass params for the query that you can use to filter massive data sets, and it helps to manage client-side paging. I would try to subclass instead, intercept, and remove.
Is your pl/sql program accessed via a URL and mod_plsql? If so, then you can use "flexible parameter passing" and the variables get assigned to an array of name/value pairs.
Define your package spec like this...
create or replace package pkg_name
TYPE plsqltable
IS
TABLE OF VARCHAR2 (32000)
INDEX BY BINARY_INTEGER;
empty plsqltable;
PROCEDURE api (name_array IN plsqltable DEFAULT empty ,
value_array IN plsqltable DEFAULT empty
);
END pkg_name;
Then the body:
CREATE OR REPLACE PACKAGE BODY pkg_name AS
l_count_value number;
l_start_value number;
PROCEDURE proc_name (name_array IN plsqltable DEFAULT empty,
value_array IN plsqltable DEFAULT empty) is
------------
FUNCTION get_value (p_name IN VARCHAR) RETURN VARCHAR2 IS
BEGIN
FOR i IN 1..name_array.COUNT LOOP
IF UPPER(name_array(i)) = UPPER(p_name) THEN
RETURN value_array(i);
END IF;
END LOOP;
RETURN NULL;
END get_value;
----------------------
begin
l_count_value := get_value('count');
l_start_value := get_value('start');
end api;
end pkg_name;
Then you can call pkg_name.api using
http://server/dad/!pkg_name.api?start=3&count=3

Categories

Resources