Wikipedia definition:
In computer programming, an application programming interface (API) specifies how some software components should interact with each other.
I've seen some people consider an api of a library just as documentation. Like on api.jquery.com they show how the jquery library gets used. I've also seen people define an api as the visible parts of a library.
I understand how web api's work: There's an interface which you can use to interact with a webapplication using JSON or XML, e.g. youtube api. So I could get information about a youtube video or playlist.
I've read that there are different types of api's. Web api's, library api's, OS api's etc.
Here are some examples that I hope I can clear my confusion with.
Example 1
If I'd include a library in C++, then the header files would be the API? What about an api like Win32/Winapi. Why is this called an api and not a library? Don't I just include it into my source code and start using it?
Example 2
If I want to use a library in C# I'd add a .DLL to my bin folder and tell the compiler I want to use the library (i.e. using System.Web). Would the api just be all the public members (hence the visible parts) in the class that is written in the library?
Example 3
Lets say company X has written an MMORPG game but they do not have a website api. I want to make a windows application and I'd like to make it possible to view any character within my app. How would I communicate with the game to get this data? Where is the api written? How can I view it?
And what kind of an api would an operating system have? How could I use it? Any examples?
API is a contract between service provider and a service consumer (your program). This is it. How is it done, it's implementation specific.
A contract in a way that provider agrees to "If you call function X with parameter Y I promise you the result will be Z.". But client also agrees to "call function X with parameter of type T" and not any nonsense.
Ad1: Your code is a library. It can implement many hidden functions, eg void Nuke_hidden(double lat, double lon); which can strike any place in the world. But you can choose to not expose this method. Instead, have some other one which takes an enum parameter limited to New York, London, Moscow.
Now how your code does something is the body of your library. What you allow your consumers to do with it, is part of your API. Your contract specifically allows bombing only those 3 cities, and forbids bombing any other place.
Ad2: You got it. Exactly.
Ad3: If someone doesn't expose and document an API, it's usually because they don't want you to write such program : ). However they must have some sort of API (even if they never call it such), which the client uses to communicate with the server.
An API is just a definition how to interact with a software component. For example, an API for ebay could contain a function call to create an auction and a function call to retrieve all bids for an auction.
The API is neither some piece of software, nor the documentation, nor a DLL. The API is an abstract definition of how to "talk" to a piece of software. How it is implemented depends on the developer that provides the API.
Of course, to tell other programmers how to use your software, you need to provide documentation of the API. That is: What calls are available? Which parameters do they require and accept?
So, regarding example 1) The header file would define how to use your API using C++. Just like for Windows. Windows has an API (that is: an interface applications can use to create windows, textboxes, etc.). The header files define how to use that from C++.
Regarding example 2) A .NET DLL is a way for a piece of software to interact with an API from managed code. You could say that every class in C# defines an API in that it has public members.
Regarding example 3) Not every piece of software provides access to its internals to other software. For example: Word does have an API you can use to create add-ins. Other software does not provide such an API.
Related
I would like to quickly list all Google Cloud projects in an organization, without AppScript folders.
gcloud projects list can be very slow. This documentation is about speeding it up, but does not show how to retrieve the Appscript folder which is used for filtering. Can that be done from the command line?
Also, gcloud projects list does not have a way to filter by organization. It seems that that is impossible as projects are not linked to their organization except through a tree of folders.
The documentation shows a way of walking the tree, apparently with Resource Manager API, which might do the job, but only pseudocode is shown. How can this be done with gcloud -- or else with Python or another language?
And if there is no way to accelerate this: How do I page through results using gcloud projects list? The documentation shows that page-size can be set, but does not show how to step through page by page (presumably by sending a page number with each command).
See also below for a reference to code I wrote that is the imperfect but best solution I could find.
Unfortunately there isn’t a native Apps Script resource available to work with Cloud Resource Manager API.
Although, it is possible to make a HTTP call directly to the Resource Manager API projects.list() endpoint with the help of UrlFetchApp service.
Alternatively, using Python as mentioned, the recommended Google APIs client library for python supports calls to Resource Manager API. You can find the specific projects.list() method documentation here.
On additional note, if you happen to use a Cloud project to generate credentials and authenticate the API call, you may want to enable Cloud Resource Manager API on your project by following this URL.
I’d also recommend submitting a new Feature Request using this template.
Here is some code that lists projects in an organization as quickly as possible. It is in Clojure, but it uses Java APIs and you can translate it easily.
Key steps
Query all accessible projects using CloudResourceManager projects(), using setQuery to accelerate the query by filtering out, for example, the hundreds of sys- projects often generated by AppScript. The query uses paging.
From the results
Accept those that are the child of the desired org
Reject those that are the child of another org.
For those that are the child of a folder, do this (concurrently, for speed): Use gcloud projects get-ancestors $PROJECT_ID to find the projects in your organization. (I don't see a way to do that in Java, and so I call the CLI.)
Is there anyway to convert or import AIML files to Dialogflow or Lex for creating a chatbot? I am hoping for a way to incorporate open source AIML files into an NLP chatbot framework like Dialogflow or Lex, and so far my googling has produced no avail.
I found a way to create a Dialogflow bot using CSV, and I wonder if this is a case of converting AIML into CSV? Is it feasible or a fool's errand?
Much appreciation for your advice, guidance, and brainstorming!
Keith Sterling has a way listed on his github page using python 3. It also has a full step-by-step implementation with screenshots and was just updated a few days ago. It’s AIML 2.1 compliant as well.
Also, it is completely free. DialogFlow itself has both free and paid tiers (as you may know) but his program is open source.
Here’s the link:Program-Y github Repo
By way of background, this is an AIML Interpreter (which is to say it is a way for you to deploy your AIML files under various circumstances). So while the link in the OP is more direct, this gives you more options.
For example this allows you to use your same files in:
Google Assistant
A Web Client
Messenger
Telegram
Alexa
Cortana
DialogFlow
etc
And because this is REST you only interact with your main implementation and this in-turn updates all client bots.
This helps you keep an updated central set of AIML files and is also lower on overhead.
Set-up:
First sign in and then click Create Agent.
Give you bot a name, and ensure the language and timezone is what you need them to be, and then click:
Create Intents
First, delete the 2 existing intents:
Default Fallback
Default Welcome
Next, create the intents for integration with Program-y (the name of the Repo).
There are 4:
Launch
Quit
Help
Query
Launch Intent
Click Create Intent
Enter your training phrases
select event, and then,
under fulfillment, choose web-hook
Quit Intent
Carry out the same steps as above, this time naming it Quit, but this time do not select an Event and use the following phrases:
stop
exit
leave
quit
Help Intent
Again carry out the same steps as above, this time naming it Help. Again do not select an Event and use the following phrases:
help
what can I ask you
help me
what can you do
Query Intent
Finally carry out the same processes, but this time name it Query. Again do not select an Event, but this time we have one training phrase
query
This time, however, add a parameter as follows:
Connect Endpoint
Finally we need to set the endpoint that DialogFlow will call each time it identifies an intent.
On the left hand side menu bar, click Fulfillment link. Click Enabled and then enter the URL that should be called which Program-Y is running on as a Google client.
The API endpoint is always /api/alexa/v1.0/ask So combine this with the ngrok URL, gives you https://87e27269.ngrok.io/api/alexa/v1.0/ask
To save this click 'Save Endpoints' and you are ready to get your client up and running.
Scroll down to the bottom and click Save.
I know that’s a lot of info and it may look overwhelming however there are screenshots and a walkthrough at the link:
Program-Y github Repo
No, currently there is no way to do this. There is no straightforward way to translate AIML files to Dialogflow or Lex JSON import formats. The basic structure of how the conversation is handled is different. Although you can find the idea of Intent, Entities and Context in AIML (specially v2.0) you would need to do a lot of manual effort to adapt it.
I would recommend extracting the patterns -what the user says- and the templates -what the chatbot responds- from AIML, import it to the framework you want to use and adapt manually the context and entities.
I was wondering how I could link my application to kraken.com server.
For example, making a login activity that sends the username and password to the server and if it's correct, open another activity.
The kraken's API is given by the following link: https://www.kraken.com/help/api
The problem is that I don't know how this API exactly works. How can I make HTTP Request and what is json? Consider I'm new in this area (API).
So firstly, JSON stand for Javascript Object Notation, it's a syntax for exchanging or storing data.
I'm assuming you're using Java since you're using Android Studio.
Looking at Kraken's API page: https://www.kraken.com/help/api#example-api-code
They don't currently have support a 3rd party Java Library for API access. So you would be looking a using a RESTful approach.
Here is an example of how to use that approach in Java: https://www.mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/
have been with mvc for a little while. the usual case when an action returning json, it is initialized by ajax in the view and the view is expecting info inside the json.
is there a case the action returning json to the view and is caught by something else instead of javascript? Thanks.
Yes, a JSON API can be consumed by a large variety of clients. It can be the browser sending an AJAX request, but it can also be a desktop application fetching data from the Internet, a server-side job scraping the data for analysis, etc.
For example, let's say you're running a stock exchange website, and you're publishing current stock values as JSON. You can use that JSON on your website to display the data, but you (or any other developer) can also write a desktop application which will get that data and process it on a local machine (to, for example, show the user which stocks they should buy). Or aggregate data from different sources.
Many websites make their APIs public, so that third party developers can write alternative clients, integrate the API's functionality in their own products, and so on. For example, GitHub's APIs are public - the GitHub website can utilize them for the AJAX requests, and GitHub for Windows can show you the list of repositories you own by making a request to that API using C#'s WebClient.
I am pretty new with R. What I am trying to do is to be able to load a URL from another application (Java) which will run an R script and output a JSON so my application can work with it.
I understand there are some frameworks like shiny which act as web servers for R, but I can't find documentation on those frameworks on how to pass parameters via the URL so R can use them.
Ideally I will need to call a URL like:
http://127.0.0.1/R/param1/param2
And that URL will call an R script which will use param1 and param2 to perform some functions and return a JSON which I will then read from my app.
If you have not done so yet please checkout [DeployR]. You can also post questions to the DeployR Google Group for help.
For full disclose I am one of the authors of DeployR
Overview
DeployR is an integration technology for deploying R analytics inside web, desktop,mobile,and dashboard applications as well as backend systems. DeployR turns your R scripts into analytics web services, so R code can be easily executed by applications running on a secure server.
Using analytics web services, DeployR also solves key integration problems faced by those adopting R-based analytics alongside existing IT infrastructure. These services make it easy for application developers to collaborate with data scientists to integrate R analytics into their applications without any R programming knowledge.
DeployR is available in two editions: DeployR Open and DeployR Enterprise. DeployR Open is a free, open source solution that is ideal for prototyping, building, and deploying non-critical business applications.
DeployR Enterprise scales for business-critical applications and offers support for production-grade workloads, as well as seamless integration with popular enterprise security solutions such as single sign-on (SSO), Lightweight Directory Access Protocol (LDAP), Active Directory, or Pluggable Authentication Modules (PAM).
I am pretty new with R
Prefect. DeployR is intended for both the Data Scientist as well as the application developer who might not know R.
What I am trying to do is to be able to load a URL from another application
(Java) which will run an R script and output a JSON so my application can work with it.
DeployR does this quit well. To aid in the communication between your application
and the DeployR server (that will be executing your R) there are the DeployR Client libraries.
Depending on your needs, DeployR has out-of-the-box 'client library' support in:
Java-client-library: https://github.com/deployr/java-client-library
.NET-client-library: https://github.com/deployr/dotnet-client-library
JavaScript and Node.js-library: https://github.com/deployr/js-client-library
DeployR also supports the RBroker Framework
should your use-case or runtime anticipate a high-volume workload or the need for periodic, scheduled or batch processing.
I understand there are some frameworks like shiny which act as web servers for
R, but I can't find documentation on those frameworks on how to pass parameters
via the URL so R can use them
DeployR acts as your analytics engine through its APIS. Basically think of it as
turning your R scripts into secure analytic web services to be consumed like any
other web service.
Pass parameters
Passing parameters to an R Script in DeployR is easy, however you have to understand that you are passing parameters to an R Script from a language that is not R. As such, there is some 'Data Encoding' that needs to be done. For example, turn your Java String into an R character or your Java boolean to an R logical...
The DeployR Client library or RBroker makes this easy.
It sounds like you are using Java, so first review the Java tutorial java-example-client-basics https://github.com/deployr/java-example-rbroker-basics to give you some context then checkout the many Java examples under java-example-client-data-io https://github.com/deployr/java-example-client-data-io.
The example source is fully available so that should give you everything you need
in order to understand how to do basic I/O from your application to the DeployR server for your R analytics.
Ideally I will need to call a URL like:
http://127.0.0.1/R/param1/param2
I suggest using the DeployR Client libraries for your communication as described above, it does just that.
As always post questions to the DeployR Google Group https://groups.google.com/forum/#!forum/deployr for help.
You have some options to do that, IMHO OpenCPU is a nice one.
It's the simplest open source way to implement a web server to provide R computation as a REST service.
The creator of OpenCPU is the same author of jsonlite package, and you can easily get and pass json parameters with OpenCPU, as you can see here.
Another way to implement REST API web service in R is a plumber package (formerly rapier). It uses function decoration approach within special comments:
# myfile.R
#* #get /mean
normalMean <- function(samples=10){
data <- rnorm(samples)
mean(data)
}
# service.R
library(plumber)
r <- plumb("myfile.R") # Where 'myfile.R' is the location of the file shown above
r$run(port=8000)
Then invoke it:
curl "http://localhost:8000/mean"