I have an endpoint that accepts two different operations, GET and DELETE.
Can I route requests to the same endpoint to different services based on operation in my dispatch.yaml?
This is how I would like to do in my dispatch.yaml:
dispatch:
- url: "*/customer/example/uri/"
operation:GET
service: aservice
- url: "*/customer/example/uri/"
operation:DELETE
service: anotherservice
No, dispatch.yaml can only route based on url.
Related
I have three different services in an App Engine.
I have 3 different routes, each of which should be routed to different services.
api.carspecialsxxx.com
Target => default (Welcome page)
api.carspecialsxxx.com/api/v1/...
Target => apiv1 (API V1)
api.carspecialsxxx.com/api/v2/...
Target => apiv2 (API V2)
How do I realize this in the dispatch.yaml
dispatch:
- url: "api.carspecialsxxx.com/*"
service: default
- url: "api.carspecialsxxx.com/api/v1/*"
service: apiv1
- url: "api.carspecialsxxx.com/api/v2/*"
service: apiv2
The order of the dispatch rules matters, the first pattern match wins.
The pattern you have for the default service actually matches the requests for the other 2 services as well, so it wins - all requests are being sent to the default service, none makes it to the other services.
You need to put the least specific patterns (the rule for the default service in your case) after the more specific ones. In your case that would mean placing it last.
But since the target of that last rule would be the default service you can completely leave it out - requests which don't match any rule patterns in dispatch.yaml file (evaluated in their order in the file) will be sent to the default service anyways.
I have a app
abc.appspot.com
Now, I want a url abc.appspot.com/blog. This url should serve from abcblog.appspot.com. I don't want a redirect.
Is this possible with dispatch.yaml
Basically, I want to introduce a blog in my app, but from a different appspot.com.
You can use the default routing by routing via URL or you can use routing with a dispatch file.
For your case I think creating a dispatch file will be the suitable way to do what you want since it will override the App Engine's routing rules and you can define your own custom routing rules.
To create a dispatch file you should put it in your root directory of your default service and you can define up to 20 routing rules in the dispatch file.
An example from the documentation:
dispatch:
# Send all mobile traffic to the mobile frontend.
- url: "*/mobile/*"
service: mobile-frontend
# Send all work to the one static backend.
- url: "*/work/*"
service: static-backend
You can check this to see how to properly configure your dispatch.yaml.
Is there a way via the dispatch.yaml file to dispatch a request to the right service based on the version and the service name ?
I mean, I have this request:
https://va4-0-0-dot-api-acceptance-dot-myapp.appspot.com/auth/user
It is sent by my api-acceptance service but I'd like it to go to my auth-acceptance service.
I have written in my dispatch those rules, but it does not work...
- url: "va4-0-0.myapp.appspot.com/auth/*"
service: auth-acceptance
- url: "api-acceptance.myapp.appspot.com/auth/*"
service: auth-acceptance
According to the documentation, the URL pattern that you're using:
https://[VERSION_ID]-dot-[SERVICE_ID]-dot-[MY_PROJECT_ID].appspot.com
will be bypassed by the dispatch.yaml file, so it's not possible to reroute the request this way.
Using the above pattern you are already being very specific to which service and version you want to route the request.
So either you change the URL to https://[VERSION_ID]-dot-auth-acceptance-dot-[MY_PROJECT_ID].appspot.com/auth/user or use a default routing which can later be overriden by a dispatch.yaml.
I'm using the angularjs-rails-resource project to wrap my http rest services.
One thing I didn't find in documentation is regarding cache, some of my methods should access the server only once and cache their response.
Is there an easy way to achieve this?
You can pass options to $http through your resource configuration (i.e. httpConfig) like so:
return railsResourceFactory({
url: '/books',
name: 'book',
httpConfig: {
cache: true
}
});
I currently route any request where the path starts with /app to a single static file, that does routing using Javascript.
Now, I'd like to support Google's ajax crawling protocol, which means I have to return HTML snapshots at any url that starts with /app and ends with ?_escaped_fragment=.
I have these two handlers:
- url: /app\?_escaped_fragment=
script: main.app
- url: /app(/.*)?
static_files: static/pages/app.html
upload: static/pages/app\.html
But requests to /app?_escaped_fragment= are still routed to the static page. Is there a way to match the query parameters?
I know I can route /app(/.*)? to a script that returns either the static page, or a snapshot based on the presence of the query parameter, but serving static files is a lot cheaper, so I'd like only requests with the query parameter to hit my app server.
While it would be nice, if you read the spec, the handlers section is for REGEXP matching on paths only, not query params. If you design your app using RESTful principles, you can easily convert your query param access to URI-based access. Just route based on /app/escaped_fragment/.* and in the handler function, inspect the rest of the path to find which specific resource of type escaped_fragment is being requested.
This isn't something you'd do in app.yaml. Those requests should still be routed to your handlers, where they can check the request parameter and return either JSON or HTML as appropriate.