For a Resource Name find the appropriate HTTP Rest URL for it.
With the help of the below Google Doc, for some resources name to URL mapping is working fine
Doc:
https://cloud.google.com/apis/design/resource_names#resource_name_vs_url
Example:
Name Format:
//cloudresourcemanager.googleapis.com/organizations/ORGANIZATION_NUMBER
URL:
https://cloudresourcemanager.googleapis.com/v1/organizations/ORGANIZATION_NUMBER
Basically adding HTTPS scheme before the name and the API major version before the resource path this works fine.
But the problem is this conversion scheme is not consistent for some resources if we form URL with this approach it will differ from the actual URL
Example:
Name Format: //compute.googleapis.com/projects/PROJECT_ID/
Formed URL: https://compute.googleapis.com/v1/projects/PROJECT_ID/
URL in Google Doc: https://compute.googleapis.com/**compute**/v1/projects
Compute Engine API Reference: https://cloud.google.com/compute/docs/reference/rest/v1
Other resources apart from compute also have actually different URL from the generated one using the above method.
Queries are:
Apart from the mentioned way is there any way to map resource names to URL
What are the best practices in such conversion
Apart from manually mapping each name to URL is there any generic way
Is there any API which provides this mapping, Like pass, a resource name and URL for it will be returned(On the internet I didn't found one)
Google APIs have a discovery document.
In that JSON file, there are 2 fields revelant for this question: rootUrl and servicePath.
To construct a proper URL for the API, concatenate both values.
More details in the discovery service docs.
Related
I have a multi tenant API and I am trying to RESTIFY it using wso2. I am trying a way to pass the tenant value in the url.
localhost:8290//tenant/api/...
https://tenant.xyz.com/api/...
I tried İntegration studio and i managed to pass a literal tenant value in http endpoint by creating a property named {uri.var.tenant} and setting it to tenant name. However, I don't know how can I take the tenant name from here
localhost:8290//tenant/api
and pass it here.
https://tenant.xyz.com/api/
I also tried using the APIM publisher page with no success.
As I see, there are 2 parts for your question.
How to parameterize the backend URL.
How to read the path parameter from the fronting API that is being called.
For the first one, the method you have followed is correct and an example can be found at https://apim.docs.wso2.com/en/latest/integrate/examples/endpoint_examples/using-http-endpoints/#example-1-populating-an-http-endpoint-during-mediation . What's remaining is to read the path parameter and to populating {uri.var.tenant} which is the second point.
For the second point, you can create and API definition with the URL templated. See the property URI Template at https://apim.docs.wso2.com/en/latest/reference/synapse-properties/rest-api-properties/ you can find an example of the usage at https://apim.docs.wso2.com/en/latest/integrate/examples/rest_api_examples/setting-query-params-outgoing-messages/#reading-a-query-or-path-parameter
My API is a request that can potentially have spaces in the pathParameters.
/data/{id}/hello/{Some message with a space}.
A sample request would be /data/23/hello/Say%20Hi
My angular code from the frontend encodes the request URL that is sent out to the AWS API Gateway but I get the following error.
`The Canonical String for this request should have been
'GET
/data/23/hello/Sayr%2520Hi`
My API gateway has a velocity template the decodes the parameters using $util.urlDecode()
I'm facing the same problem.
I've been stuck for a day.
If you are using HttpApi it cannot be solved.
Nevertheless, if you use RestApi I managed to make this work.
Specifically, you should use the URL Path Parameters.
You should:
Add a resource containing the /{variable}
Add a Url Path Parameter in the Integration Request Configuration with name variable and mapped from method.request.path.variable
Notice that the solution may depend on the integration type that you are using.
In the screenshot below you can see how I'm redirecting all the received traffic to a NetworkLoadBalancer.
The resource has the variable /{proxy+}, the endpoint URL has the {proxy}, and, in the URL Path Parameters, I've configured the mapping method.request.path.proxy.
I keep seeing comments on how to do URI versioning in API Gateway, and these all say the same thing,
Do not create the version path (/v1) as a resource in your API. Instead, simply call you API "Names V1" and start creating the resources (/names). When you want to make a breaking change and create a new version of the API, we recommend you create an entirely new API called "Names V2". Once again, simply create your resources without the version path.
To bring the two APIs together, you can use custom domain names. A custom domain name in API Gateway includes both a fully qualified domain name and a base path. Create two custom domain names:
myapi.com/v1 -> points to the prod stage of the Names V1 API
myapi.com/v2 -> points to the prod stage of the Names V2 API
However, when you try to create a Custom Domain Name with a "/" in it, API Gateway responds with "Invalid Domain Name". So if you try to do it on the mapping, you get something similar mentioning the special characters you can use, and "/" is not one of them. So your only option is to use the Stage variables which these posts mention the challenges of doing it that way.
Additionally, if you just make it "v1" with no slash, then we are unable to have a custom domain like "api.whatever.com". Then makes the custom domain be specific to an API area that needs to be versioned. Ex. "stores.whatever.com". This causes each API to have their own subdomain.
URI-based Versioning for AWS API Gateway
API Versioning with AWS API Gateway
Sorry for asking a new question, but I'm not allowed to add a comment on the posts.
I'm not sure I understand the request here, let me try to clarify. When a request comes in to your custom domain name api.whatever.com, API Gateway needs to determine where to send the request. API Gateway will look at the path and then determine if there are any API:STAGE mappings for that path. You can configure an empty base path mapping on a custom domain name, but then all requests without a path to that custom domain name will be routed to the API:STAGE mapping. It seems like you're trying to route requests to either api.whatever.com or stores.whatever.com, you can do this with two custom domain names each with their own empty base path mapping. For example:
Custom domain name1: api.whatever.com
api-id: 12345
stage: Live
api-mapping-key: NULL
Custom domain name2: stores.whatever.com
api-id: 67890
stage: Beta
api-mapping-key: NULL
Your clients will have to specify the proper domain name when calling your APIs.
I have an AWS API Gateway set up with a custom domain name one the format api.example.com. I have a api.example.com/prod stage and a api.example.com/dev stage, but I would also like to be able to modify the response returned on api.example.com.
What I want is very similar to how the GitHub api behaves. Where https://api.github.com/v2 access version 2 of the api, and https://api.github.com/v3 access version 3, but https://api.github.com gives a custom response.
In my case I would like to have a small static html page on api.example.com, but a custom json response (like on api.github.com) is fine, anything more helpful than {"message":"Forbidden"} would do.
I know I set up base path mappings to the dev and prod stages in the custom domain window (as my partially redacted settings below), but I would like to add a empty path as well, and have that point to another API with just a GET method on the root resource that returns a small static html page. API Gateway does not allow combining an empty base path mapping with non-empty base path mappings (for a good reason I assume), but it feel there should be some way to achieve what I am trying to set up.
Anyone who knows a way to achieve this using AWS API Gateway?
I'm developing an Angular Universal serverless app in AWS Lambda/Api gateway. The app works perfectly using the standard api url ( {api-id}.execute-api.{region}.amazonaws.com/{stage}/) but now I'm trying to deploy it in a human-readable url using Api Gateway's Custom domain names.
For that I followed the docs and troubleshooted using other stackoverflow's questions, but now I'm faced with a problem and can't find another question that looks like my problem.
I have already setup the API, the custom domain name (which created a cloudfront distribution) and a Route53 A-type ALIAS routing to this new cloudfront distribution and the routing kind of works.
The problem I'm facing is that when I'm using the new domain name, the angular app cant find assets like CSS, Icons,etc. All of them works fine using the standard api url but not with the custom.
To do some debugging I configured Api Gateway to log requests to CloudWatch, and I can see that when I'm using the standard url, the resource path log is like this:
HTTP Method: GET, Resource Path: /main.4d57a71fd195330e8ee9.js
But when I use the custom URL the same log is like this:
HTTP Method: GET, Resource Path: /development/main.4d57a71fd195330e8ee9.js
I'm guessing it has something to do with the base URL in the custom domain name configuration of Api Gateway, I tried changing it to everything I could think of but nothing fixed it.
Here is a screenshot of my Api Gateway configuration.
Api gateway - Custom Domain Names configuration
Tell me if you need anything more and sorry if bad english.
Thanks in advance.
EDIT: I should make clear that I'm trying to point to the "development" stage of my api
I believe you simply need to reconfigure your custom domain. It should be sufficient for you to change the following;
In "Base Path Mappings" section change Path from "/development" to just "/"
I had similar problem. The only workaround for me is to set baseHref to "/" in environment.serverless.ts and have one single mapping in custom domain name from "/" to "{YOUR-API}:production".
This breaks direct url access to the API but access via custom domain name works fine.