Yii2: How can I pass an array to RESTful Web Services [closed] - api

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
How can I pass an array from frontend to my API? I tried to pass it via body param
Yii::$app->request->getBodyParam("arrayParam")
But am not able to get that array it returns a string

You can handling API for easy way - none optimal solution- by adding
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
to your action, then you can return any array you want....
but if you have folder like fronted, back-end and API, you need to work or process data in API controller, and do not pass data between these ends by array or session...
Example:
public function actionView($id)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$user = \app\models\User::find($id);
return $user;
}
useful link:
Create Api End

Related

API best practices for batch operations [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 12 months ago.
Improve this question
We have a requirement to develop an API with CRUD operations that supports batch inputs for each of create, read, update and delete operation.
For ex.
Request for "Create" will be an array of [Name and Value]
Response = array of [Name and Value]
Request for "Update" will be an array of [Name and Value] -> Values of each Name are updated here
Response = array of [Name and Value]
Request for "Delete" will be an array of Names
Response = 204 no content
Request for "Read" will be an array of Names
Response = array of [Name and Value]
We will use POST for Create and Update (or PUT?); However to support batch inputs (max array size=100) in the request body for Read and Delete, I think the option is to use POST (instead of GET for read and DELETE for delete). Is there any downside to this approach? Are there guidelines for implementing such batch operations?
If you are trying to communicate operations that aren't worth standardizing, then you should be using POST.
In particular, PUT has a specific meaning in the transfer of documents over a network domain, and you shouldn't be trying to hijack it.
A request body with DELETE is a bad idea. Don't go there - use POST.
A request body with GET is a bad idea. You should either figure out a way to get the information you need into the target URI of the request (ie, each different body you might send is a unique resource) OR you should use POST.
Using POST isn't a great answer, because you hide from the HTTP application the fact that the request semantics are effectively read only; hiding that information reduces the number of intelligent things that general purpose HTTP components can do. POST is still a much better choice than trying to stick a body on GET.
At some point in the future, we expect the working group to produce some standard for new HTTP method aka GET-with-a-body, and that might give you additional options.

I am trying to implement Permisions in asp.net boilerplate webApi [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am trying to implement an AppService called Plug, I want to use User Role and Permissions and I can't seem to get it working, I applied the steps above and I am not winning.
namespace Sprint.Plug
{
[AbpAuthorize(PermissionNames.Pages_PlugEntity)] //Permisions
public class PlugAppService: AsyncCrudAppService<PlugEntity, PlugDto, Guid>, IPlugAppService
{
public PlugAppService(IRepository<PlugEntity,Guid> repository):base(repository)
{
}
}
}
Have you applied the permission to the database for your user/role in AbpPermissions table?
if you are already authenticated and you consume that API, [AbpAuthorize(PermissionNames.Pages_PlugEntity)] attribute will check you have permission in table AbpPermissions isgranted or not.
Ex :

Is there any way to set JSESSIONID while doing scraping using scrapy [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am writing a code for spider in Scrapy for this website
[ https://www.garageclothing.com/ca/ ]
this website uses jsessionid.
I want to get that in my code(spider)
Can anybody guide me that how can i get
jsessionid in my code.
Currently i just copy paste the jsessionid from inspection tools of browser after visiting that website on browser.
This site uses JavaScript to set JSESSIONID. But if you will disable JavaScript, and try to load the page, you'll see that it requests the following URL:
https://www.dynamiteclothing.com/?postSessionRedirect=https%3A//www.garageclothing.com/ca&noRedirectJavaScript=true (1)
which redirects you to this URL:
https://www.garageclothing.com/ca;jsessionid=YOUR_SESSION_ID (2)
So you can do the following:
start requests with the URL (1)
in callback, extract session ID from URL (2) (which will be stored in response.url)
make the requests you want with the extracted session ID in cookies

API call for user count in Chrome Web Store? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I have an extension in the Chrome Web Store and I like knowing roughly how many people are using it via the "N users" and ratings on its page.
However, I don't really like loading the whole "product" page just to see a couple of numbers and thought I'd try to make a little widget that would display it instead. However, I can't find any API documentation for the Chrome Web Store.
I would a call like /webstore/api/v1/appid.json to exist, but the closest things I've found in searching only concern the Licensing API.
Is there an official Chrome Web Store API for user metrics?
This is no such API.
You can use Google Analytics inside an extension to track users manually.
If you don't need anything fancy, just a number of installs and users, there is My Extensions extension, it will track those numbers for you.
Copy and paste the snippet below wherever you want in the body of a html document saved with a ".php" extension.
<?php
//URL of your extension
$url = "https://chrome.google.com/webstore/detail/ddldimidiliclngjipajmjjiakhbcohn";
//Get the nb of users
$file_string = file_get_contents($url);
preg_match('#>([0-9,]*) users</#i', $file_string, $users);
$nbusers = str_replace(",", "",$users[1]);
echo $nbusers; //Display the number of users
?>
You can also do this client-side only (at least on your end) by using a cross-domain tool. This snippet will grab the number of users displayed on the Chrome webstore page for an extension (up-to-date as of April 28, 2018):
var chromeExtensionWebstoreURL = 'https://chrome.google.com/webstore/detail/background-image-for-goog/ehohalpjnnlcmckljdflafjjahdgjpmh';
$.getJSON('http://www.whateverorigin.org/get?url=' + encodeURIComponent(chromeExtensionWebstoreURL) + '&callback=?', function(response){
var numUsers = ((""+response.contents.match(/<span class="e-f-ih" title="([\d]*?) users">([\d]*?) users<\/span>/)).split(",")[2]);
console.log(numUsers);
});
In the future, Google may change the class name of the user count span, in which case you just need to update the regex appropriately.

Library or API that gathers user info from social networks [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I'd like to gather user data in a web-based intranet application similar to rapportive, gist and xobni. These services gather and display facebook profiles, twitter streams, linkedin profiles, etc. based on the user's email address in your inbox.
Is there a 3rd party library or API (free or paid) that would provide this kind of data from social networks based on a person's email address? I'd rather not have to go through and create calls for all these different services, not to mention maintaining all these APIs. If there is already a service out there that does the work of search and aggregation that would be so useful.
The application is in C#, so a C# library or wrapper for the API would be nice but definitely not a requirement.
Rapleaf... that is the magical service that you can use to find social media data. They have both batch and API REST services.
Yes Rapleaf appears to be the way to go. But applying for the API key appears to take some time; they may or may not grant an API key. any experience with this?
If you're a somewhat industrious coder and you only have a select few social networks to search, it isn't so difficult to write simple library functions to access their APIs yourself. They all have different limits on how much searching you are allowed to do, so keep the idea of throttling in mind.
Here's an example of a php function I use to search for people Batchbook by email address, you should be able to modify this to get data from most typical REST APIs:
function getBatchbookContacts($orgname, $apikey, $emailSearch, $page) {
$url = "https://{$orgname}.batchbook.com/api/v1/people.json?auth_token={$apikey}&email={$emailSearch}&page={$page}";
$request = new HttpRequest($url, HttpRequest::METH_GET);
$request -> setContentType('application/json');
try {
$response = $request -> send();
if ($response -> getResponseCode() == '201' || $response -> getResponseCode() == '200') {
$result_json = $response->getBody();
return $result_json;
} else {
throw new Exception($response -> getBody(), $response -> getResponseCode());
}
} catch (HttpException $ex) {
throw new Exception('Internal Server Error: ' . $ex -> getMessage(), 500);
}
}