Hands on - how to create an API gateway

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this demo um i will provision an api gateway and create a few apis then what a few apis and how you can protect them with the apigee so first things first we need a virtual cloud network um i mentioned that the api gateway is a network attached device so from the oci console i'm going to create a virtual cloud network i need to select a compartment where i will be placing my resources this is my compartment now i already have a vcn created but i will create a new one just to show you how to do it i'll be using the vcn wizard bcn with internet connectivity and i will just name it webinar vcn 2 and leave all the default settings this will be very quick and it is done okay so now that i have my vcn um i can create my gateway dpi gateway uh you can find it from the menu under developer services api management and gateways and you can pin it as a shortcut okay now again i'm going to create a gateway here to show you the options so we have webinar uh now the first option that you can choose is the type whether you want this to be a public or a private gateway if it's public it will have a plug a public ip and you can access it from the internet for demo purpose i will keep it as public now i will select the virtual cloud network i will use my vcn2 and a subnet and since i want this to be a public uh gateway i will select a public subnet from my vcn now i mentioned that the gateway supports custom domain names if you want to do so you can select from here custom dns and you will need to attach your certificate and click on create so let's have a look at the gateway so my gateway is public has a public ip address and a host name so this is the network attached device next i can begin creating my deployments the deployments will be the base urls of my apis i will create a deployment when you create the deployment you have two options you can create it from scratch or you can use um a deployment specification in json format but for demo purpose i will be doing it from scratch so basic information provide a name for your deployment i will call it the api about graphics i would call into the api and the 1.0 version i can um already add policies so i can add policies for authentication corpus originally or support create limiting i have the login policies by default the log level is set to information you could change it to lower level so for now um i will not be adding any policies here so click next and i will define my route so my route is how's this i will select the method and these are the http uh methods i will choose get and my back end in this case i'm going to use an http backend and i will provide the url so this is a public rest api that i'm using for demo purpose i have an option now to add policies for request for response for response caching and for logging let's have a look at some of the policies available so i could do validations this is checking that a certain header or query parameter exists in my requests i can do body validation to validate that the body is a specific content type i can do transformation to add remove or modify headers and query parameters on the response header transformations again to add remove or change headers i can enable response caching and i can change the logging for this route for now i'll just leave everything as is and i will add one more route and i'll be using here a context variable idea again http and as for the backend url here is my backend url so what i'm trying to do with this is to retrieve a specific house a house with a specific id which i pass as a template or path variable this is a context variable in api gateway and i can use this to build my back end path a bit more in a bit more dynamic manner so i can access these context variables using request dot both if my variable is part of the path i could use request.query if i want to take that value from the query parameters or i can use headers as well i will leave all as default with for now click on next and create my deployment now let's get um ready to test it so in order to test it i need the endpoint this is my endpoint here i'm going to use postman take postman here okay what i want to do in postman i want to invoke this deployment i'm going to copy my deployment url and remember that i created uh two rocks one was houses the other one was how this left house so i want to try this okay my deployment is ready so let's see if i get a reply from this okay it appears that something is wrong let me tell you what is wrong in this case i mentioned that the gateway is a network attached device the network is your first level of protection so i have my subnet here and my subnet has an attached security list this is the default security list when you create a vision uh at least using the wizard so my default security list only allows this uh these three rules so oh it only allows tcp traffic on port 22 which is ssh for my gateway i need four for three for https access so what i'm going to do in order to make this work i am going to create a security list for my api gateway i'll call it security list and i will add an ingress food with destination port clustering for http access now to keep it simple i am going to allow all traffic and create my security list and i'm going to attach it to my public subnet this is where my gateway is provisioned okay i added and now i'm going to try it again and it is working here i have the houses as you can see these are houses from the song of ice and fire saga game of thrones okay let's try also uh the second method the house by id so i'm going to take this and i'm going to add here my house id and i'm going to use 378 so this is the house that i know and here i have my result this is house targaryen okay now the nice thing using postman is that i can use variables and i can also organize my requests and save them into collections so i will i actually have a collection that i created here earlier so i have my houses request and i have an environment here with values that i can use dynamically in my requests so um to try this i want to add now from my gateway i want to uh use here the actual hostname of my gateway let's copy this i will use it in postman modify my url here let's take it easy if i take it from the endpoint of my deployment so i will change this okay so this is the url of my api gateway okay and now it's probably easier for for you to see um how the url is built so you have the url of the api gateway and then you have the prefix of your deployment which is this one demo api 1.0 and then you have the routes so i'm going to call this again and here are my houses uh here is my house by id again i'm using a nice construct from postman uh to pass the pot variable again this is the house targaryen did the same as before okay let's have a look what else we can do so i'm going to use the same deployment and add a few more routes in here so let's edit the deployment next on the roads i'm going to add another route i'm going to call to name this as hello the method is going to be get and for type i'm going to choose the second uh backhand type available which is oracle functions if i can expose an oracle function using api gateway um i need to select my function so my function is actually in another compartment so and i'm going to use the hello button function okay uh there's one more thing that i want to do now i want to add a rate limiting policy and just for the sake of demo i will keep it at 1 request per second usually what it happens when i hit the limits i'm going to apply the changes next so i have my route next and save changes okay while this is happening while my deployment is getting updated you can start to see to see already some metrics are coming in and i can see a summary of the number of api requests and responses bytes sent and received the latency which is the total latency of my endpoints but also the internal latency of the api gateway and the backend latency of my actual combat service meanwhile i'm going to prepare my call to the function deployment is ready now first time i do this it will actually not work i get the 500 internal server that's because i need to do a setting in my policies so for functions to be able for the gateway to be able to invoke function functions i need to give it permissions and you do this from identity and security identity policies i have a policy already created in my compartment to give apiga quiz access to functions so what what you need in here is a statement to uh which has this format allowing user to use functions family in a compartment so this is the compartment where the function is created in my case my function is in the malaria compartment and i have a condition here request principle type api gateway and this is the compartment id where i have my gateway and i needed this compartment id let's get it in another tab departments okay this is my new compartment and i need the compartment oc id i need to add it into a statement in my policy so i'll add another statement here copy from before and replace the compartment oc id what this statement is doing it is allowing api gateway located in this compartment to use functions that are located in the valeria compartment my case so i'm going to save the changes let's see if meanwhile my hello is working i think it will work the first time when you invoke a function it takes a bit longer for the function to initiate and it's working we got 200 okay and i also got a response hello you
Info
Channel: Oracle Learning
Views: 805
Rating: undefined out of 5
Keywords: oracle, database, cloud, cloud apps, enterprise cloud
Id: hES55nIQH0Y
Channel Id: undefined
Length: 15min 55sec (955 seconds)
Published: Tue Jul 20 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.