Data scraping from the web using dart - dart

I am making a web application, in which i need to scrape the web to get some data. I can't see a way to do this without using the dart:io.HttpConnection which is not imporatble for web apps. What should i do, Can i make a server application and then use it with a client version, or something else?

You would need to build this server side since the browser security model does not allow you to connect to other origins than the one that served your application (unless of cause you can use JSONP or CORS to do the scraping but I doubt that). So you need to create a service on your server that uses HttpClient to do the scraping for you and then call this service from your client using XMLHttpRequest

Related

Can a web api sit on remote server?

or must it be on the same server as the app calling it? I am new to web api so i am going through some tutorials, but they all assume the web api is part of the mvc app. Also, they show the calls to the api being done with javascript, but I want to make the calls in my MVC app controller. Is this possible?
You can host a Web API anywhere.
The only special thing to have into account when the Web API isn't in the same server that a web site that uses it, is that, by default, the Web API doesn't accept requests from a different domain. For example, if the web site is in "server1.com" and the Web API in "server2.com", then the calls to the Web API from the web server will be rejected.
If this is the case, you need to configure the Web API server to enable CORS (cross origin resource sharing), so that it accepts requests from a different domain. If you want more info about this, please look at this document:
Enabling Cross-Origin Requests in ASP.NET Web API 2
The Web Api can live wherever you want it to. Is typical to see a limited API used mostly to handle AJAX for the MVC application live with the MVC application, mostly because it makes it simpler to construct URLs to the endpoints. If you host the Web Api externally, then you'll have to hardcode the API endpoint URLs, as there's no way to use something like Url.Action to generate them automatically, any more. Regardless, it's a perfectly acceptable way to handle things.
You will probably at least want to add the base URL for the Web Api as an app setting in your Web.config, though. That way, you don't end up with hardcoded references to a particular domain strewn all about your app. That makes moving your Web Api to a different domain much easier, especially when talking about going from development to production.
It is also entirely possible to use a Web Api within your actual controller actions. You'll just need to use something like HttpClient to connect to it and issue requests.

Authentication of Web API and AngularJS SPA app

I have two servers - web and app. The web server (IIS) serves only static files - HTML/CSS/JS. On executing the JS, the client gets the data from the app server (HTTP service using Web API, self hosted with OWIN). I need to bring in authentication so that my data as well as the content is restricted.
I can use SSL, I can pass username / password to the web api, have it authenticated and get back a token. I can pass this token for future web api requests. In my client app javascript (done using AngularJS), I can also maintain info whether the user is authenticated, what roles she has etc. (for user experience). But for security, I need to be able to ensure the html content requested (in the web server) is also having authentication and authorization done. How can I achieve this?
Should I change my app to make the web server call the app server internally rather than from the client? I can use MVC controllers or ASP.NET, but since I was using AngularJS, I thought it is not required, and is kind of a duplicate. Should I ditch pure .html files and move to .cshtml?
How is this done in the Angular + .NET world, when you data comes from a different server than your htmls?
We've been using JSONP with REST type api to do cross domain AJAX calls, but our Angular client code is within .cshtml files in a .NET project. Sounds like the simplest solution is to use the app server internally- I would go with that

How to serve a frontend that gets data from a rails API server?

We have decided to go with a rails JSON only API server for our new project since different clients need to access it.
I'm thinking about how the frontend could be served to the browser. As I see it I could
EITHER
have a javascript heavy client built on top of a client side MVC like
Backbone that accesses the API server directly
OR
have the frontend server make some of the API calls and render the html to the client. Some APIs would still be accessed from client JS. A lot of the processing and routing logic would reside in the server.
I'm hesitant to go with the first option due to it being more heavy on the client and less SEO friendly. Also making the client an SPA is not a priority.
I'm looking for advice and comments on the second option. Is this approach recommended ? What would be a good choice for the FE server in that case ? I'm thinking of having a separate rails FE server that talks to the rails API server.

Monitor server requests

I have a ASP.NET MVC3 web application. To get data from third party, my application makes several HTTP requests from server. I want to see all the http requests made to the third party from server for each page loads. I have installed glimpse from nu-get package. but I could not see any remote HTTP calls made from server. I am debugging my application in my local machine. is it possible to get this information using glimpse? if not is there any other tool can help me out here?
Thanks!
Unfortunately, Glimpse does not currently show HTTP requests your application has made - but that sounds like a great feature!
You do have a few options:
Create a custom tab using Glimpse's extensibility model. You could tap into whatever HTTP client you are using and expose the data.
Additionally, you could leverage Glimpse's Trace Tab to trace out messages about your HTTP requests.
Finally, you could use ANTS Performance Profiler which recently added a feature to see all the HTTP requests an application makes, in addition to CPU level timing information and SQL queries. (And it has a free trial!)

Setup a Rails app to avoid having to use CORS

I am running a MAMP server with default settings (port 8888) locally, and I have a Rails app running on its default port (3000).
In production, I will be having a Kentico server running that will need to run GET, POST and PUT requests via ajax to the Rails app.
Right now though, I am just wanting to set it up in a way so that locally I can develop this out without having to implement any form of CORS. Since POST and PUT requests are part of the mix, there's no way I can use JSONP.
Is there any way to do this, and if so will it translate to the same way of doing it once in production?
CORS would be the most standards compliant way of doing cross-domain communications. But other options include:
Set up a proxy server to proxy requests on the server-side to your Rails app
Use an iframe-based solution. This involves setting up a page on your server that makes same-domain XHR requests. You'd then include this page on the client-side using an iframe, and talk to it via inter-frame communication mechanisms such as postMessage.
Here's an overview of the latter technique: http://softwareas.com/cross-domain-communication-with-iframes

Resources