In the last lecture, we learned what API Gateway does in general and which features it offer on a very
high level and we will use many of these features throughout the course, so no worries if they're not all
set right now
but now I want to focus on the meat of API Gateway.
I selected a method here on the resources and this is an endpoint we can actually hit with a request
because an endpoint is made up of two things, our resource,
so the path to which the request should get sent and the method, the type of request because of course, there
is no request.
There are different types of requests, you can send a POST request, a GET request
and here, we get an endpoint which will react to get requests being sent to this path
and this path of course is always appended to our general URL of that API,
so to this URL. Here at the end, we would attach this path
and if we set a get request to the path, we would hit this endpoint.
Now as soon as we do hit this endpoint, we go through this cycle here on the right,
so what is this about? It basically depicts the flow of data in our API.
We got a client and this of course is the app or whatever which sends the request and conveniently, we can even
test that here, so if we click on test, we can send a test request from within API Gateway so that we
don't have to set up a client to do the testing.
We'll do that nonetheless later in the course but having this test method is great and that's all this
does,
we can just simply test a request being sent by a client.
As a side note, you see these markers, these orange markers?
You can always click them to get some information about the specific item they sit on
and once you click that away, they're gone
but you can always bring them back by clicking on show all hints.
So that might be useful if you're not clear about something or if something is confusing.
However we just talked about the client, client is sending a request,
OK we got this.
Now we hit the method request box,
what does this actually mean?
Well this cycle depicts how an incoming request is handled by API Gateway and method request, this
first box defines how requests reaching this endpoint should actually look like.
It's like a gatekeeper,
we can reject requests if they don't fit a certain schema and I'm not just talking about the schema
we might have set up in any of our request data models here,
I'm talking about more.
Let's have a look at the method request box by clicking on method request,
here you can see there are a couple of things we can configure,
for example we can set up authorization.
Now it's set to none right now but we will later in this course learn how we can add authentication
here.
We can say if an incoming request is not authorized
and again, we will learn how to authorize incoming requests, if it is not authorized, we simply block it, end
of the road.
Nothing else happens,
it simply gets rejected with an error code and message and we're done. The same for validation, we can
validate the incoming request, we can validate it for one of the three things we see down here.
We can check if the query parameters attached to the request fit our scheme, query parameters are
the thing after the question mark at the end, like here in the URL. We can also check if the headers
attached request fit our scheme or our needs and we can finally check the request body
and here, we can connect it to a model we might have created
so that we say incoming data should let's say always have a name which is a string and age which is a number
and if the incoming request body does not fit that schema, it also gets rejected with an error message
and code and we stop right here. And we do this by setting up here if we want to validate the body, validate
everything or just query string parameters and headers.
So this is how we can set up validation
and finally, here's this API key again. We can require an API key and therefore lock our API to anyone
who doesn't have such a key.
Now that is the method request box,
what it does is it acts like a gatekeeper,
it ensures that incoming requests have a certain shape, have certain data, fulfill certain requirements.
As soon as this is met, we continue. So with what do we continue?