WSO2 API Manager: Error adding test API (api with only root context) - api

Our service provides a simple test API:
GET /api/test/v1 which simply returns "Test Success"
Trying to add this to the WSO2 API Manager version 1.8.
Name: test
Context: test
Version: v1
Visibility: Public
Now what should be added under Resources? As the API does not have any sub-resources, tried adding as:
URL Pattern: /
Resource Name: /
When clicked "Implement", got the error "Error while adding Swagger Definition for test-v1"
Please suggest what is the right input for "Resources" in this case (where API has only a root context)

Leave for default resource pattern. This will enable all HTTP verbs (ie: GET/PUT/POST/DELETE/OPTIONS) to accept all resource patterns.
Eg: URL Pattern: /*

Related

is apiKey security defined in Open API 3.0 not enforced when running in AnypointStudio?

I have an endpoint defined in OpenAPI spec :
paths:
/employee:
get:
parameters:
- name: sourceSystem
in: header
description: ID of organisation
required: true
schema:
type: string
security:
- apiMyHeaderKey: []
components:
securitySchemes:
apiMyHeaderKey:
type: apiKey
description: 'API Key to authorise requests.'
name: MyKey
in: header
So I have two headers - 'sourceSystem' which is mandatory and also 'MyKey' which is of type 'apiKey'
The above spec is being developed as a Open API spec 3.0 as a YAML file and then I am importing it into Anypoint Studio ( Mule 4.4 runtime )
When I am running the API locally , 'sourceSystem' is being mandated by mule BUT 'MyKey' is NOT .
So I am wondering why ?
In the real world - this API will be deployed behind a gateway so all incoming requests will first hit the gateway and then request will hit our api .
So I think the API key check will happen in gateway and if all good only then will the request get forwarded by gateway to API
This is an educated guess , not sure if this is why mule is not enforcing apikey though it is defined in the specification ?
why is mule ONLY enforcing 'sourceSystem' and not 'MyKey' authorization ?
Thanks

Change API Gateway Name when using Serverless Framework

The Serverless framework has made it very easy for developers to create an API gateway connected to a lambda function. like this
hello:
name: hello-handler
description: blablabla
handler: /lambda-functions/hello-handler.handler
role: HelloRole
package:
include:
- lambda-functions/hello-handler.js
events:
- http: GET hello
My question is how can I change the name of the API gateway that is going to be created?
Based on the doc, this should do the trick.
provider:
...
apiName: custom-api-name # Use a custom name for the API Gateway API

How to use default request templates when using the serverless framework?

I understand that I need to specify a request template for the API gateway in order to gain access to the request headers. The Serverless docs say:
"Serverless ships with the following default request templates you can use out of the box:"
The default templates look like they provide access to what I want (i.e. request headers), but how do you tell Serverless to use them?
The "default request templates you can use out of the box" are referring to a lambda integration, not a "default" integration, where you leave the parameter blank. If no integration is defined, then it is the default integration. So, under http, add "integration: lambda".
However, that being said, you should still have access to the headers when you do not specify the integration.
Lambda Integration
https://serverless.com/framework/docs/providers/aws/events/apigateway/#example-lambda-event-before-customization
functions:
create:
handler: posts.create
events:
- http:
path: posts/create
method: post
integration: lambda
Default Integration
https://serverless.com/framework/docs/providers/aws/events/apigateway/#example-lambda-proxy-event-default
functions:
index:
handler: handler.hello
events:
- http: GET hello

AWS API Gateway : route error

I created my API in EC2 instance of AWS. when I'm deploying my API in to AWS Api gateway. API Gateway provided me with a link. When I used that same link in postman to access my API, I'm getting the following error, despite providing IAM credentials.
The Error I'm facing is
{
"message": "No method found matching route / for http method GET."
}
I had the same problem and solved it. The problem is in the Invoke URL you're using. To fix this, please correct path: check the Deployment API link + double check what method you want to call.
You may need to add some more path variables after "/". E.g., "test", whatever, so path finishes with method you'd like to invoke.
I created test project for you, please see screenshot with example. So, in order for script to execute math operation, e.g. "add", you add "/math/add", not default invoke URL:
Good luck!
Check the "Auth" section of your method request in the API gateway.
I had the same response until I set Auth to "AWS_IAM"

Use Oauth in Swagger API

I'm building API using swagger and so far I created get/insert/update and delete jobs, and now I'm trying to use Oauth to secure my API
I have used
securityDefinitions:
job_auth:
type: oauth2
authorizationUrl: http://localhost:10010/auth
flow: implicit
scopes:
write:jobs: modify jobs in your account
read:jobs: get your jobs
And in my /get function i used
`paths:
/jobs:
# binds a127 app logic to a route
x-swagger-router-controller: job
get:
description: Returns the job list
# used as the method name of the controller
operationId: getAllJobs
responses:
"200":
description: Success
schema:
$ref: "#/definitions/GetJobsListResponse"
security:
- job_auth:
- read:jobs `
In swagger editor , now it shows
Security
job_auth (OAuth 2.0) Authenticate(Button)
Flow implicit
Authorization URL http://localhost:10010/auth
Scopes
write:jobs modify jobs in your account
read:jobs get your jobs
now i want to access job list using
http://localhost:10010/jobs
but it gives something like this
{
"message": "unknown security handler: job_auth",
"code": "server_error",
"statusCode": 403
}
can anyone help me how to access http://localhost:10010/jobs and set
Authenticate in Oauth properly, I'm new to this