In this video, we will understand how to design or rambles using Design Center in any point platform. But before we go ahead and design, let's talk about a simple requirement. Let's assume that I am developing applications for bank. And we want to do an API, which will expose the bank's assets like customers and one customer can have multiple accounts and one account can have multiple transactions. So if you are defining if we are defining an API or designing an API for this customer account management is trying to identify the resources, the resources, what we want to expose our customers, accounts and transactions. So even before we Go to design first let us identify one of the you are eyes We are going to expose in this REST API.
So how do you represent customers? By using what you are right? every resource must be uniquely identified by URL. So how do you identify customers as the reverse? Maybe by using slash customers? Is it?
Yes. And how do you identify accounts slash accounts? And how do you identify transactions slash transaction so I'm just listing out right now. So that we can actually write the same thing in ramify later. Now another thing is how to get a list of all customers in bank what can be the Ura and what can be the method may be something like slash customers. Slash iD iD is a You are a variable.
And what SDP method get is it GET request to slash customer slash customer ID may give our customers how to register a customer. Normally we use post to actually create a new resource for us to watch what slash customers, okay? How to get people, this one was slash customers, I won't get all customers, right. So this one was slash customers, and how to get customer information for a specific customer ID slash customer customers slash ad. And what good is the method get? How to update the customer information, maybe batch requests or put requests I write my patch to, again, slash customers.
Slash customer ID How to delete a customer should be same right? So slash customers slash ID but now the method will be what? Delete is it similarly how to get accounts are accounts of a specific customer, hey, I don't want all accounts. I want all accounts for a specific customer ID is very tricky tricky. First of all, let me identify customer by ad, it should be less customers slash ad. See, this identifies a particular customer.
Now what we want for this customer, we want account so slash accounts section the best practice would be to navigate from parent touching. customer has accounts you can say customer entity is a parent of accounts. It's always better to navigate from parent to So, first you identify the customer by using slash customers slash ID and you all the accounts. So, again here the method can be get, how to create a new account of course, put request for a POST request to slash accounts. Okay. Then how to get information of a specific account 30 maybe it is slash accounts, slash ID and methods what get right get similarly How to delete a particular account with specific account ID.
First of all slash accounts, slash ID will identify the account and then applying a delete method on it will delete an account out update upon On a specific ID First of all, again identify the account by using our consciousness. And my third, I can say put our patch patch. Similarly, how to create a new transaction post request to slash transactions. First how to get transactions of a specific account ID now I think you should be able to visualize, I don't know all transactions, I want transactions by account ID. So first of all identify the account by using slash accounts slash ID. Then for this account, I want transactions or slash transactions and the methods I can get.
How to get transactions for specific transaction ID so it's simple class transactions slash transaction rates. GET request, right? So we want to design an API using ramble for this one. Let us get started. Actually, now I'll go to design center. to design your API's, we always go to design center.
In this design center, I need to create an API specification. So here go to create, create what? Create API specification. Actually on Design Center, you can always create a mule application also, till we have created our new applications in studio itself, but we can also create new applications in design center as well. I'm going to show you how to create a new application using design central right now. Let's go and create an API specification.
Okay, I want to give a name, I will say my bank API create certain going to create an APA specification project. Okay, you can see that in design center. It has opened the ID for designing your API's. And here you can see that on the left side the files are the main file name is my bank API dot ramble. I don't want this tip so I'll carry the tips. And here in the middle, you can see the first line is saying that we're going to use a ramble versus this one point zero and tight lock my API is given as my bank API can modify it.
Every. Every API will have a base URL. So I want to the base URL. Actually, once I press enter, you can see at the bottom, what all keys are possible in Rommel are listed out. Basically, I want to give a base URL for my API. I'll click on base URL, and give my API URL so http colon slash slash localhost, or I can do anything any of the host but I'm giving localhost 801 slash API, I want this to be a base URL.
See, as I as I type in on this one on the right side, you can you can see that the UI is getting updated and shows that the base URL is this one. Okay, now, I want to write the URLs First of all, whatever I'm going to expose, so what we want less customers rate Now you're writing in grammar. Whenever you whenever you are is a lead, it has to be suffix with colon. So I want to expose class customers slash accounts. And then slash transactions. These are the high level resources, right?
So remember, syntax is very important in ramel, after every line how to use colon after the key of the Ura, right? Okay, under slash customers. Again, I want the sub resource class customer slash customer ID, right? I want to do that every. So you have to identify the sub arrays, and for every sub you array here to keep two spaces as delimiters. Remember, in Rational two spaces are de limiters for every line.
So under slash customers, I want slash ID and remember to use colon after this So he said, customer slash ID you can see the pain points slash customer slash customer slash already listed. And we also want slash customer slash ad slash accounts, is it the ad? Similarly, slash accounts slash account ID. And we also identified as transactions. Right? So again, slash transaction slash transaction ID.
So what I did is I listed out all the urs whatever I want to support in my rammer first, and I visualized the pain points that all the pain points listed on the right side is it then once I'm done, I need to decide what all methods I want to support what all MIME types I want to support, etc, and start expanding each of them step by step. So let's get started. Actually, I have created nice documentation. So in my lab docs, which you might have downloaded, there's a file called as 15 rambled part one, following this one. So step by step. Let me follow this one and I'll explain you.
So I have completed up to this part. Now I want to add the methods, whatever I want to support. So go back to my designer. I want to support getting post request for slash customers. So Learn it there are two spaces under that I will select Get. And again I will take my cursor to the same level and then I will say post.
So right now you can see first class customers on the right side I have configured getting post to be supported. And for slash customer slash, ID, I want to get requests so we'll type get calm. And for slash customer slash ID slash accounts I want to be in support get. So like that for each and every UI, identify what methods we want to support and write it for now, for saving time. What I will do is I'll copy paste. So what I have done is in my lab docs, I have given you a zip file called as ramel docs.
I have extracted this ramble docs here And there is a ramble file. I'll open this zero to Acme banking API ramble and I'll copy paste the whole content I'll explain you since of typing each and everything I'm copy pasting nothing here much the rational question is on Panzer as usual title is now changed to Acme banking API. And first class customers getting pushed or supported. First Class customers last Friday getting patches supported. Catch and delete are also supported. And forced slash customer slash account slash Id only slash ID slash accounts only get a support.
So like that I wrote what all methods I wanted support for each and every resource. Then I want to add the base URL And also media type let us see. So after this I learned this worry if I'm not adding here you can say that you can see on the right side base your is not defined read us now not worry about the base you will write I want to do something also called as a media type. So, basically for all the resources, I want a default MIME type or media type as application slash Jason. So, for all the, your eyes when a response is given, the default media type is application slash Jason. Okay.
But of course, they can override this one let me show you under slash customers slash get. I want I tapped it here. Once a tab after get here are the keys, whatever I can do response Second, describe responses. And under responses, what is the status code? Let's say 200 I want support. And also 404 Also, I want to support legislation 404 So here I'm seeing that for GET request 204 04 I am support.
So like that you can, you can, you can decide what all the status codes you want support for responses. Okay. Then what I want to do is for 200 response letters, I won't describe more about 200. So you won't actually, after I give the body what the body type, I can specify Jason and also XML I won't support both. So basically, here we can see that for response status code 200 the body and It can be either JSON or XML. If I don't specify anything by default it will be whatever I gave on the top.
Okay. So right now I left the body empty that means the MIME type by default should be Jason okay. select that. I want to add all the status codes up and I want to copy paste from this 03 let me just copy paste and I'll explain you just reverse trends of wasting time and explaining understand automatically. See here, I I configure here. The default media type is Jason.
And for GET request, I want to support 200 and body I didn't do it for post I want to support font status code 201. And when the response is 201 for post, I want a response header caller's location. So I described with that and body I didn't specify anything specifically. And under slash customer slash Id get request. I won't support response to the score 200 and body a MIME type it in specifically so the default one will be applied. Similarly for that request to slash customer slash Friday status code which I want to support is 204 for delete 200 so like that, for each and every UI, I configure the response success status codes and headers that I want you to understand one small thing.
See here post request first class customers is it not same as post request for slash seconds. See, I'm right entering for the first response status code which I want to support us to 01 and there should be at our current location and the body same thing here also this this duplicate is it and same thing also is therefore post request to slash transactions. Is it so, I want you to observe that there is some duplicate, even if you see request, maybe I guess could request also is m 202 01. And what about here? batch request 204. So that's not duplicate.
So there are some duplicates here right? For post at least you observed for all post. Whatever I wrote is looking like duplicate will eliminate it Next view observer if you observe on the right side it's mostly describing okay slash customers. We have gotten cost for slash customer slash customer ID we have get patch and delete. It's very nice that so till now, we have added success status codes for all the you are okay. Let me go to the document.
Next we want to add 404 status code under get customers let us see. For GET request to slash customers I want to also add 404 status code that again 404 body actually underbody I want to describe some properties and What I want is according to my document I want properties like status code. It should be of type string and message. And also I want to be of type string string is a predefined type. Actually what all three different types of data you can see here you can see string, integer Boolean daytime daytime only. These are all the standard types we'll see using all of them slowly.
Here I want methods to mystery. So, whenever 404 is going for slash customers, I want the body of 404 to contain this property status current message I updated according to my document. Similarly, I want to add 404 response body to all this slash customer slash customer, slash accounts and all sins of typing. What I do is I want to copy paste From the 04 banking API ramming so that I can explain you so copy and paste Okay. Now you observe that wherever required I configured 404 or slash customer customers first class customer slash Id also for zero for anything that is duplicate almost same thing like your I have given it here. Yes, I intentionally made duplicates to understand to tell you about some interesting things later, here was a four digit request also 404 same thing I added four GET request to slash accounts also added 4044 GET request to slash a construct it also added for delete request also added.
So, wherever possible I added all the 404 status code, but for all places wherever I have that at 404 is it not the same Same thing. Yes. Okay. So let me follow the next things. Similarly, if you want to add 500 status codes, so all 500 credit scores, I have our EML file again here. Copy paste this content so that can save some time.
So just understand that here I have added Pfizer of three status code. But one thing I want to observe the properties are same, like I haven't 404 officers. So, actually don't worry. How do you understand what all status codes might want to support? Maybe in your requirements document. You will be getting whatever status codes you want to support.
What should be the return body property, you'll be getting a document. So you need to understand how to write the syntax for Randall here. I'm not telling what are the standard status codes to be supported and how it should be. But once you identify the status course, this is a way to configure how to identify what are status codes for your APA to be defined. It's up to you to take a decision, is it okay? So I added all the 500 status codes also as per my document.
So long let us follow same document. I want to add XML and JSON to response body and also I want to add headers, let's see how to add headers. So coming back to slash customers for response for request, basically, for every GET request, there might be some request headers. So I want to configure all headers. So under the I can configure headers and I want some standard headers like accept, but I want to accept header to be optional. So if you want such accept added to be optional here do question mark.
So here I am describing that GET request for slash customers can have an optional Agricola x. Similarly, for GET requests of class customers want or define some query parameters, what you can do is, you can select query parameters. And let's say I want a query parameter called as name, customer name. I can define customer name and is it a mandatory one, I can specify required equals to false And what is a type of it here I can specify customer name as to be your string. And maybe I won't give a default value. Let's say default value is Siva and example I can do that also I can view everything these are all things which I can actually describe.
So like that I can define a number of query parameters also for a particular method, and also headers also you want it. So now what I want to do is I want to add headers for all other things and copy paste the document in 06 request Yep. So wherever possible headers are added as per the document like this. Okay, then what? I want to add caching related headers. So let me open this 07 and I'll show you how to add caching little headers.
So here is the one caching related headers. Let's see. fee for GET request in the response 200. I want to specify that there will be caching with current headers like cache control x class, etc. Just copy paste the same thing. So we configured some headers as well, like accept the request header, and in response, cache control headers, how to specify.
Here I'm specifying the expires is of type, date time. Is it like that? Step we have decided what will request response headers and we can create a document instead. So as a next step, we'll see how to define our own custom data types. In the next video, see you next video.