在同一应用程序的不同模块中使用Google端点 [英] Using Google endpoints in different modules of the same app
问题描述
我对使用Google App引擎和Google平台的其他Google服务进行开发相当陌生,我想创建一个包含使用端点的不同模块的应用程序(以便它们可以拥有自己的生命周期)。
我在使用api路径挣扎,因为我不知道如何将请求路由到好的模块。
我的目录树是这样的:
/ myApp
/ module1
__init__.py
main .py
/ module2
__init__.py
main.py
module1.yaml
module2.yaml
dispatch.yaml
module1.yaml
应用程序:myapp
运行时:python27
线程安全:true
模块:module1
版本:0
api_version:1
处理程序:
#端点处理程序必须映射到/ _ah / spi。
#Apps将请求发送到/ _ah / api,但端点服务处理将
#映射到/ _ah / spi的请求。
- url:/_ah/spi/.*
script:module1.main.api
libraries:
- name:pycrypto
version:2.6
- name:endpoints
version:1.0
module2.yaml
application:myapp
runtime:python27
threadsafe:true
module:module2
version :0
api_version:1
处理程序:
#端点处理程序必须映射到/ _ah / spi。
#Apps将请求发送到/ _ah / api,但端点服务处理将
#映射到/ _ah / spi的请求。
- url:/_ah/spi/.*
script:module2.main.api
库:
- 名称:pycrypto
版本:2.6
- name:endpoints
version:1.0
dispatch.yaml
调度:
- url:* / _ ah / spi / *
module:module1
- url:* / _ ah / spi /.*
module:module2
所以我希望我的端点可以在相应模块的某个地方被调用('_ah / api / module1'或'module1 / _ah / api')。我不知道要在不同的.yaml文件中放置什么。我甚至不知道我在做什么是对的,或者可能的。
感谢您的回答。
您可以在不同的模块(现在称为服务)上托管不同的端点。正确解决它们的方法如下:
$ b $ p $ lt; code> https://< service-name> -dot-< your-project-现在,假设您已经按照您的描述进行了操作 module1
https:// module1-dot-< your-project- id> .appspot.com / _ah / api
以类似的方式, module2 API:
https:// module2-dot-< your-project-id> .appspot.com / _ah / api
如果您想深入了解此URL架构的工作方式(包括版本,这是此处等式的另一个重要部分),请阅读解决微服务问题以及紧随其后的部分使用API版本
I'm quite new to development with Google App engine and other Google services of the Cloud platform and I'd like to create an app with different modules (so they can have their own lifecycle) which use endpoints.
I'm struggling with api paths because I don't know how to route requests to the good module.
My directory tree is like that:
/myApp
/module1
__init__.py
main.py
/module2
__init__.py
main.py
module1.yaml
module2.yaml
dispatch.yaml
module1.yaml
application: myapp
runtime: python27
threadsafe: true
module: module1
version: 0
api_version: 1
handlers:
# The endpoints handler must be mapped to /_ah/spi.
# Apps send requests to /_ah/api, but the endpoints service handles mapping
# those requests to /_ah/spi.
- url: /_ah/spi/.*
script: module1.main.api
libraries:
- name: pycrypto
version: 2.6
- name: endpoints
version: 1.0
module2.yaml
application: myapp
runtime: python27
threadsafe: true
module: module2
version: 0
api_version: 1
handlers:
# The endpoints handler must be mapped to /_ah/spi.
# Apps send requests to /_ah/api, but the endpoints service handles mapping
# those requests to /_ah/spi.
- url: /_ah/spi/.*
script: module2.main.api
libraries:
- name: pycrypto
version: 2.6
- name: endpoints
version: 1.0
dispatch.yaml
dispatch:
- url: "*/_ah/spi/*"
module: module1
- url: "*/_ah/spi/.*"
module: module2
So I'd like my endpoints to be called with the name of the corresponding module somewhere ('_ah/api/module1' or 'module1/_ah/api'). I don't know what to put in the different .yaml files. I don't even know if what I'm doing is right, or possible.
Thanks for your answers.
You can host different endpoints on different modules (now called services); the way to correctly address them is as follows:
https://<service-name>-dot-<your-project-id>.appspot.com/_ah/api
Now, let's say you have—as per your description—module1 and module2, each one hosting different endpoints. You will call module1 APIs by hitting:
https://module1-dot-<your-project-id>.appspot.com/_ah/api
And in a similar fashion, module2 APIs:
https://module2-dot-<your-project-id>.appspot.com/_ah/api
If you want to dig deeper into how this URL schema works (including versions, which are another important part of the equation here), go read Addressing microservices and the immediately following section Using API versions
这篇关于在同一应用程序的不同模块中使用Google端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!