I want to be able to get whois data (and idn domains too) by client-side javascript. Is it possible? Maybe some free REST-like WhoIs service exists?
Try using http://whoisxmlapi.com service.
The service URL: http://www.whoisxmlapi.com/whoisserver/WhoisService
You need to specify outputFormat=json and domainName=insert_domain_here parameters..
Example URL: http://www.whoisxmlapi.com/whoisserver/WhoisService?outputFormat=json&domainName=stackoverflow.com.
Example code (using jQuery to simplify AJAX communication):
$.ajax({
url: 'http://www.whoisxmlapi.com/whoisserver/WhoisService',
dataType: 'jsonp',
data: {
domainName: 'stackoverflow.com',
outputFormat: 'json'
},
success: function(data) {
console.log(data.WhoisRecord);
}
});
HERE is the working code.
Update:
The service mentioned above is not free, but there are several free whois services that are providing HTML output and by using YQL you can retrieve the HTML as a JS. See THIS answer for more details.
Example (using jQuery & jquery.xdomainajax):
var domain = 'stackoverflow.com';
$.ajax({
url: 'http://whois.webhosting.info/' + domain,
type: 'GET',
success: function(res) {
// using jQuery to find table with class "body_text" and appending it to a page
$(res.responseText).find('table.body_text').appendTo('body');
}
});
HERE is the working code.
You need to have a look at the structure of the HTML document and select, process and display the data you are interested in. The example is just printing whole table without any processing.
What you can do if you have exec() enabled in php is create a php file with the following:
exec('whois domain.com');
and then create aa .ajax() request to the php script where you pass the domain name and output it.
An npm package called node-whois did the job for me. It's server side JS, not client side, but perhaps this will help someone.
i'm also trying to find out a free whois provider with JSON output, couldn't find one. But, there are WHOIS windows client provided by Microsoft and like someone mentioned above, we can use PHP/cgi to get the details.
I'm not sure whether there's any WHOIS lookup/query provider gives JSON output at free cost.
BTW, i just found this phpWhois from sourceforge.net, would be a good starting point to use whois from the server. This is the library used by RoboWhois / RubyWhois provider as well.
You could use whois npm module
https://www.npmjs.com/package/whois
Also in mac terminal, try this to see whois data
whois google.com
Related
I can't for the life of me figure this out, it seems like it should be straight forward but it's just not clicking.
I have an ES6 app that I created using create-react-app. I've got all the templates and layouts set up for the project and came to trying to pull in data from an API that I want to sit inside the app - like a botched MVC where React handles the views and I run the models and controllers in PHP.
So I have a function in one of my components that I want to fetch some data. I use the fetch() function (I know this isn't yet compatible with a number of browsers but that's a problem for another day) to fetch a relative path from the component to the model I want to load, however the fetch function treats my path as a call to the base URL followed by the request. So with the site running on localhost:3000, I run the following code in my getData() function...
let test = fetch('../models/overall-stats.php').then(function(response) {
console.log(response);
return response;
});
...the URL that fetch hits is then http://localhost:3000/models/overall-stats.php which simply resolves back to the index.html file and loads the app, rather than the PHP file I'm requesting.
If I need to hit that PHP file to get my data, am I wrong in using fetch? Or am I just using it incorrectly? If I shouldn't be using fetch what's a better approach to this problem I'm having?
When I run this on an apache server (after building and deploying) I can get the fetches to work fine (apache recognizes the structure of the URL and hits it as I am expecting) and I hit the file no issues, but I need to be able to work in a local development environment and have the same functionality. The app will end up being deployed live on an apache server.
Any help would be greatly appreciated.
I knew after sleeping on this it would be very straight-forward... I simply had to move my models and controllers into the public directory for them to be accessible. I'll be putting in authentication to the models so that they can't be hit directly, but only through GET requests.
Why don't you just use something like ${baseUrl}/models/... ?
Also for solving browsers problem with fetch you can import the Polyfill or simply use axios (my choice)!
Maybe you can try to use ajax to get or post the data from server, just like this:
$.ajax({
url: '../models/overall-stats.php',
data: {
},
type: 'GET',
dataType : 'json',
success : function(res){
let obj = parseJSON(res)
}
})
or add this on top in your php file because the CORS :
header('Access-Control-Allow-Origin: *');
I'm trying to make an app using phonegap, but what I want to know is if it is possible to store information online. For example, say there is a number variable, and it is added to when a button is pushed. Could that value be saved somewhere and then a totally different device can retrieve the variable?
I looked at databases, but I couldn't really understand it. I want something that can be accessed by any device as long as It has a key or something.
Is this possible? If so, how would I do it?
PhoneGap uses JS so you cannot connect to the database directly. You should create a Web service using server side languages like PHP on external server and make ajax request on your web service. This approach is possible using PhoneGap.
Sample Code will look somewhere near:
function FetchData() {
$.ajax({
async: false,
type: "GET",
url: "Your_WebService_URL",
dataType: "json",
success: function(data) {
$.each(data, function(i, object) {
if(i==="title"){
document.getElementById("title").InnerHTML = object;
}
if(i==="home_image"){
document.getElementById("title").InnerHTML = '<img src="'+object+'"/>';
}
});
},
error: function() {
alert("There was an error loading the feed");
}
});
The web service, in this case json will throw the variables. May me somewhere like this :
[{"title":"my application"},{"home_image":"http://link.com/image.png"}]
I think this article is useful to you: Loading external data into a PhoneGap app using the jQuery JSONP plugin for cross-domain access. Also see this similar question here:
This is entirely possible.
You essentially need two components: the client interface, and the server.
The client displays the results to the users, and, using your example, waits for a button to be pushed. On the push of that button, the client would send a request to the server to increment the stored value (possibly through a jQuery.post, or get, function call).
The server page, written in php for example, receives this request, and accesses a file, or more realistically a database, to increment the value.
With some Googling, this should be very doable, but post specific questions if you get stuck.
Let me start off with saying I just figured out how to use JQuery's "$.ajax()" just a few days ago. I've been able to read local .xml and .json files.
Also, I've figured out how to use the google maps API to import dynamic and static maps. (just following the google documentation)
Now, I had an idea to use steam IDs for a school project, but I keep getting this error:
XMLHttpRequest cannot load http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=[MY_SECRET_KEY]2&steamid=76561197960435530&relationship=friend. Origin http://local.mysite.com is not allowed by Access-Control-Allow-Origin.
(I took out the key, and the generated key is suppose to allow access to http://local.mysite.com)
Here is my code:
<script type="text/javascript">
$.ajax({
url: "http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=[MY_SECRET_KEY]&steamid=76561197960435530&relationship=friend",
dataType: "json",
success: function(data){
console.log(data);
},
error: function(req,text,error){
console.log(text);
console.log(error);
console.log("DIDN'T WORK!")
}
});
</script>
Does anybody know what's going on? I can't seem to get this to work.
See this answer and the posts here. For more background visit mdn.
Essentially you're running into a security issue where the browser won't allow you to make a request from http://local.mysite.com to http://api.steampowered.com.
Do you have access to a server? Instead of making a request like this: browser -> steampowered you can make a request like this browser -> your server -> steampowered.
You're going to want to create an endpoint on your server (so that it's in your domain) that you can send a request to, that will in turn send a request to steam powered.
What language / framework are you running and we can give you example code.
We are building a service that exposes a REST Api to the clients and we are using jugglingdb to create the models and express as the server.. I was wondering if there are any modules that are useful when creating a RESTful API in node.js
I tried using restify but it seemed to be just a watered down version of express and seemed to lack some functionality i needed from express, so i switched to express.
EDIT: We have no front-end. So we are strictly a rest api service that just provides data for various clients
One approach to consider is to keep things light and simple. If you don't have a front end, you can use the Connect module alone instead of Express, which is built on Connect:
http://www.senchalabs.org/connect/
I had good luck with this approach with my Node.js RESTful API. I did end up with a few repeated patters, especially in parsing incoming post data at times. But I found the code snips were just too small to be worth putting into a module, and it offered me amazing flexibility in certain situations.
One more approach that worked very well for me: Post ALL of your data as JSON - not as post key/value pairs. Depending on your API's clients, you may be able to do this. My API client was jQuery AJAX calls from a web page. It's very easy to send a JSON post. The jQuery processData property allows this as follows:
$.ajax({
url: '/nodeAjaxHandler',
type: 'POST',
data: JSON.stringify(formVals),
processData: false,
dataType: 'json',
success: function(data) {
},
error: function(a, b, c) {
}
});
Now receiving the data in your Node server is as simple as waiting for the body text to load, then JSON.parse it into an object. Very readable and manageable. And when you change the data fields being posted and received, you don't need to change any of the interface code at all!
(And you can go one step further if you dare, and make the field names match your database field names - then you can consolidate even more code. This felt risky to me but worked brilliantly - I'm not sure what the down sides might be yet. I do escape all my field names as well as my column names in the mySQL queries.)
RESTfull API get and post data through HTTP protocol. A more progressive approach is to use WebSocket [Wikipedia] npm link. Try to play with Sails.js framework build on Express.js that use Socket.IO for flash data transfering
If you're using MongoDB (with mongoose):
http://benaugarten.com/node-restful/
https://npmjs.org/package/node-restful
I am writing a simple widget that renders a canvas participation graph just like the one's on github.
It uses the data at http://github.com/[user]/[repo]/graphs/participation
The widget works great and is basically done. The only problem I have is when I try to retrieve the json data from the above link via XHR (rather than just copying and pasting into the widget as I have been), I run into the same origin access control problem.
Is there any way I can access this information at all, either via XHR or some hidden github api feature?
I believe Github supports JSONP and CORS through its API. You could also setup a server-side proxy, through which XHR requests are made to a same-origin page which then does a server-side request to Github.
To answer your question about the proxy, yes it's very simple. I had actually done this exact thing about two years ago using Python and Tornado. I realize this isn't PHP, but it reads close enough to english to give you the idea about how it works. This particular proxy was returning a raw gist.
# /proxy/gist
class GetGistHandler(BaseHandler):
def get(self, id, filename):
url = 'http://gist.github.com/raw/%s/%s' % (id, urllib.quote(filename))
resp = urlfetch.fetch(url)
self.finish(resp.content)
It can then be consumed with something along the lines of
$.ajax({
url: '/proxy/gist',
dataType: 'JSON',
data: {
id: $('#id').val(),
filename: $('#filename').val()
},
success: function(json) {
// ...
}
});