Consuming Endpoints APIs elsewhere in App engine - google-app-engine

I have programmed and tested my API using Proto-datastore and now I'm ready to do something more with it.
As well as having generated the client library to allow apps to communicate with the API, I'm looking to create a web-based 'Dashboard' for the service (which would be based on the guestbook example). This would be also be built and hosted on the same App-Engine project. But I have no idea how to go about consuming the API in App Engine.
Importing the API and just calling the #Model.method() decorated functions won't work. I have found this but I was wondering if there's anything in proto-datastore I've missed that would let me do this?

The way I'm doing it is to access the endpoint, the same way I would access any other Discovery-based API hosted somewhere else, by using use the Google APIs Client Library for Python which is compatible with endpoints.
Normally you would build a client for one of the Google APIs using service = build(api, version, http=http) for example service = build("plus", "v1", http=http) to build a client to access to Google+ API.
For using the library for your endpoint you would use:
service = build("your_api", "your_api_version", http=http,
discoveryServiceUrl=("https://yourapp.appspot.com/_ah/api/discovery/v1/"
"apis/{api}/{apiVersion}/rest"))
You can then access your API with
result = service.resource().method([parameters]).execute()
Might not be the most optimal way, but it works like a charm.

Related

Google cloud endpoints service is not listed in api library

I'm trying to share my API (with a custom domain) with the customer( service consumer role), but this API is not listed in the API library. When he tries to open API using the link to generate API key he gots errors. The same problem I have when I try to generate API key for customers. I'm using endpoints frameworks for the GAE standard environment. Image
This one looks more like a problem with the Cloud console or the Cloud APIs, I'd better address the issue at a Public Issue Tracker (PIT), you can open one in here, and preferably add a relevant HAR file that should contain some additional information of the response message.
This will help to correctly address any ongoing service issue.

Can I change the API url of a third Party API?

I want to request a third party API on Web APP. The API example is https://api.pinesapsapi.com/request.
Can I change the URL and build a different URL with any of the external platforms or AWS?
The basic reason of the URL changing is to keep the API Url private with my developers.
Is this possible?
For Example:
https://api.pinesapsapi.com/request should look something like https://api.xhatdffsdkj.com/request or any other generic URL
If you're looking for an AWS service to specifically do this your best best would be using API Gateway.
Configure a REST API that uses a single method of /{proxy+} and configure it with HTTP_PROXY. You can then add a custom domain name to your API Gateway setup and have it proxy to this other other domain.
Alternatively you would be looking at using a proxy based solution to forward the requests to the endpoint (such as NGINX or HAProxy running on a host such as EC2).

How to access the Google Maps Directions API client-side from a library

I'd like to send requests against the Google Directions API. Google provides a Node.JS client library for the API. However, this AP is server-side only. Attempting to use it from a browser script results in a CORS failure. Multiple past answers (such as this one) indicate that this library simply can't be used in this way.
The alternative is to use the client-side JavaScript API. However, this requires adding a <script> tag to the document root. That's the wrong level of abstraction for my needs. I'd like to use a method from a library or dot-js file instead.
Following the advice given here, I'd like to ask: is there a module available through npm I can use to query the Google Directions API client-side?
It's not naively possible to access the Google Maps Directions API from the client side. Web browsers implement the Single-Origin Policy, which requires that any requests to a domain come from the same domain. Requires between domains are disallowed by default. Cross-domain requests can be enabled at the server lever by setting the right CORS headers on the endpoint, but the Google Maps servers choose not to do this.
There are two ways of working around this. One is to wrap the request using the Google API Auth library. However, I could not get this to work.
What did work was using a reverse proxy. This workaround is actually mentioned in the Google Directions API intro page (albeit obliquely). You will need to set up a server which forwards any requests to an API request, then returns that API request to the original requester. Since this is now a server-side request, SOP will not apply, and you will be good to go.
For an example implementation check out this repository on GitHub.
https://developers.google.com/maps/documentation/directions
This is the Directions API web service. It does not require adding a <script> tag.
You can make direct requests to the service as per the example:
https://maps.googleapis.com/maps/api/directions/json?origin=75+9th+Ave+New+York,+NY&destination=MetLife+Stadium+1+MetLife+Stadium+Dr+East+Rutherford,+NJ+07073&key=YOUR_API_KEY
once you have generated an API key and replaced YOUR_API_KEY in the request with your own key.

Appengine - The fast way to call others module in the same project

I have some appengine modules in my project.
I am building a "Cloud Endpoints" that will works like a API Gateway. Both in them same project.
The endpoints will receive a request and forward to another appengine module, so, when the module process the request, the endpoints will return the response to frontend.
The main reponsibility this API Gateway will be validate permissions and log informations.
The frontend sends: GET,PUT and POST methods.
I read about URLFetch to do it.
I would like to know, Is it fast to use URLFetch to to do it?
Should I use other framework to to id?
If you're on App Engine, external requests should use URL fetch regardless of if you use it directly or use your language level networking primitives. It should be relatively fast, though you should benchmark this for yourself to see if it's an acceptable latency.

How to use API as backend in ionic mobile app development?

I am having a web application built using JAVA spring which has API feature to read and write into database.
Now i have to develop an ionic mobile app for the same application. How to read and write data into database.
I know Firebase and other alternatives can do the job.
But i need my own API code(written for web app) to be used. Is there any way to achieve that?
I guess calling the respective API when the web application is live is achievable.
But how can i achieve that while developing(When the web app is under construction)
Well depending on how you set up the API this could become quite difficult.
You're saying/guessing that you can call the API when the webapplication is live. This makes me assume you've created a REST API? Or did you create a Spring MVC application?
If the webapplication is directly linked to your Spring application (f.e. going to localhost:8080/my-profile shows a page (not JSON) of your profile) then I'm not sure if you can achieve the above mentioned target.
If you get a JSON response, or are somehow able to retrieve it from the webpage, you can just simply call (in typescript:)
this.http.get('http://localhost:8080/my-profile').map(response => console.log(response.json() );
Else, you probably will have to create a basic REST API (check out Spring boot for a 5 minute setup) and provide it, either with hardcoded data or connect it with your database.

Resources