Enable Cloud Endpoint APIs in a separate App Engine

I am developing an App Engine application and plan to provide an API as well. I would like to separate this API from the main site, so I am trying to use the "modules" function to separate both applications. The main site will be the default module, and the API will be in the api module. However, I have problems with this.

Right now, my main application YAML file is as follows:

application: my-app module: default runtime: python27 api_version: 1 ... handlers: # Root handler - url: /.* script: main.app secure: always ... 

And a YAML API module file, for example:

 application: my-app module: api runtime: python27 api_version: 1 handlers: # Endpoints handler - url: /_ah/spi/.* script: api_main.app secure: always ... 

On the development server, the application is served on port 8000 and the API on port 7998.

In this configuration, my API does not work. Whenever I try to access it using localhost: 7998 / _ah / api / explorer, I get no result. If I try to start the API request manually, I get the following error: {"error": {"message": "BackendService.getApiConfigs Error"}} .

Which is strange, I also see the following lines in the development server logs:

 INFO 2014-06-15 18:00:32,368 module.py:639] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 500 - INFO 2014-06-15 18:00:32,368 module.py:639] api: "GET /_ah/api/my-app/v1/events HTTP/1.1" 500 60 

It seems that the API module is trying to pass the POST data to the default module (as can be seen from the first line of the logs).

Currently, the only workaround I have found is to add the same handlers for /_ah/spi/.* to the default YAML file, but in this situation, the separation between the main application and the API is inefficient.

Can someone tell me if the configuration I'm trying to achieve is Cloud Endpoints? Thank you very much!

+6
source share
2 answers

The same problem, I was able to get it to work after possible temptations: the only way I found was to make the cloud endopoints module the default module. Then I have: on the dev server two modules listening on different ports, you can see the read numbers in the log and on xxx.appspot.com: yourprojectid.appspot.com for the cloud endpoints and modulename-dot-yourprojectid.appspot. com for another module

+4
source

I had the same problem.

I decided to use a single file to publish my APIs. This file is listed in app.yaml. I put my APIs in different files.

 \ app.yaml \apis publish_api.py \teacher teacher_api.py \student student_api.py **app.yaml:** - url: /_ah/spi/.* script: apis.publish_api.api secure: always **publish_api.py:** import endpoints from teacher.teacher_api import TeacherApi from student.student_api import StudentApi api = endpoints.api_server([TeacherApi, StudentApi]) **teacher_api.py:** @endpoints.api( name='teacher', version='v1', allowed_client_ids=[WEB_CLIENT_ID, API_EXPLORER_CLIENT_ID], scopes=[EMAIL_SCOPE]) class TeacherApi(remote.Service): @endpoints.method(message_types.VoidMessage, StringMessage, path='teacher', http_method='POST', name='writeTeacher') **student_api.py:** ... 

So, I get each file separately.

0
source

Source: https://habr.com/ru/post/970874/


All Articles