Raml Basics -Part3

Mule 4 Indepth Api led connectivity and RAML Design
22 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.39
List Price:  €93.41
You save:  €28.02
£55.92
List Price:  £79.90
You save:  £23.97
CA$96.01
List Price:  CA$137.16
You save:  CA$41.15
A$107.15
List Price:  A$153.08
You save:  A$45.93
S$95.13
List Price:  S$135.90
You save:  S$40.77
HK$547.14
List Price:  HK$781.66
You save:  HK$234.52
CHF 63.86
List Price:  CHF 91.23
You save:  CHF 27.37
NOK kr775.40
List Price:  NOK kr1,107.76
You save:  NOK kr332.36
DKK kr487.78
List Price:  DKK kr696.86
You save:  DKK kr209.07
NZ$118.01
List Price:  NZ$168.60
You save:  NZ$50.58
د.إ257.06
List Price:  د.إ367.24
You save:  د.إ110.18
৳7,680.49
List Price:  ৳10,972.60
You save:  ৳3,292.11
₹5,842.03
List Price:  ₹8,346.11
You save:  ₹2,504.08
RM332.86
List Price:  RM475.54
You save:  RM142.67
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,491.96
List Price:  ₨27,846.85
You save:  ₨8,354.89
฿2,586.09
List Price:  ฿3,694.58
You save:  ฿1,108.48
₺2,265.39
List Price:  ₺3,236.41
You save:  ₺971.02
B$363.53
List Price:  B$519.35
You save:  B$155.82
R1,302.64
List Price:  R1,861
You save:  R558.35
Лв127.90
List Price:  Лв182.73
You save:  Лв54.82
₩96,270.48
List Price:  ₩137,535.16
You save:  ₩41,264.67
₪262.29
List Price:  ₪374.71
You save:  ₪112.42
₱4,033.94
List Price:  ₱5,763.02
You save:  ₱1,729.07
¥10,867.12
List Price:  ¥15,525.12
You save:  ¥4,658
MX$1,187.12
List Price:  MX$1,695.96
You save:  MX$508.84
QR254.93
List Price:  QR364.20
You save:  QR109.27
P994.08
List Price:  P1,420.18
You save:  P426.09
KSh9,360.69
List Price:  KSh13,372.99
You save:  KSh4,012.30
E£3,358.63
List Price:  E£4,798.26
You save:  E£1,439.62
ብር4,003.77
List Price:  ብር5,719.92
You save:  ብር1,716.15
Kz58,546.63
List Price:  Kz83,641.63
You save:  Kz25,095
CLP$67,216.99
List Price:  CLP$96,028.39
You save:  CLP$28,811.40
CN¥506.70
List Price:  CN¥723.89
You save:  CN¥217.19
RD$4,073.53
List Price:  RD$5,819.58
You save:  RD$1,746.04
DA9,418.34
List Price:  DA13,455.35
You save:  DA4,037.01
FJ$158.31
List Price:  FJ$226.17
You save:  FJ$67.86
Q543.96
List Price:  Q777.12
You save:  Q233.16
GY$14,650.29
List Price:  GY$20,929.88
You save:  GY$6,279.59
ISK kr9,815.39
List Price:  ISK kr14,022.59
You save:  ISK kr4,207.20
DH707.71
List Price:  DH1,011.06
You save:  DH303.35
L1,237.78
List Price:  L1,768.33
You save:  L530.55
ден4,025.24
List Price:  ден5,750.59
You save:  ден1,725.35
MOP$563.96
List Price:  MOP$805.69
You save:  MOP$241.73
N$1,304.33
List Price:  N$1,863.42
You save:  N$559.08
C$2,570.38
List Price:  C$3,672.13
You save:  C$1,101.75
रु9,397.27
List Price:  रु13,425.24
You save:  रु4,027.97
S/263.43
List Price:  S/376.35
You save:  S/112.91
K270.11
List Price:  K385.89
You save:  K115.77
SAR262.49
List Price:  SAR375.01
You save:  SAR112.51
ZK1,873.89
List Price:  ZK2,677.10
You save:  ZK803.21
L325.37
List Price:  L464.84
You save:  L139.46
Kč1,643.47
List Price:  Kč2,347.91
You save:  Kč704.44
Ft25,458.03
List Price:  Ft36,370.18
You save:  Ft10,912.14
SEK kr764.90
List Price:  SEK kr1,092.76
You save:  SEK kr327.86
ARS$61,327.27
List Price:  ARS$87,614.14
You save:  ARS$26,286.87
Bs483.57
List Price:  Bs690.85
You save:  Bs207.27
COP$273,218.78
List Price:  COP$390,329.27
You save:  COP$117,110.49
₡35,710.66
List Price:  ₡51,017.42
You save:  ₡15,306.75
L1,733.65
List Price:  L2,476.75
You save:  L743.09
₲524,442.73
List Price:  ₲749,236.02
You save:  ₲224,793.28
$U2,683.09
List Price:  $U3,833.15
You save:  $U1,150.06
zł283.24
List Price:  zł404.64
You save:  zł121.40
Already have an account? Log In

Transcript

Welcome back. This video is in continuation with the previous ramble part two. Right now we'll see here how to create reusable resource types and also how to create something called as crates. Firstly, what are resource types? Let me go to my API in my API designer. Actually, if you see there are some common things for all collection resources.

We can actually classify the resources whatever we have into two types. One is collection resources, and collection item resources. Slash customers represents a collection of customers right? I can say slash customers is a collection resource. Slash accounts is a collection slash transactions is a collection users. But slash customer slash customer ID.

That means it points to one Customer in the collection right? So slash customers slash customer ID is a resource is a collection item reports, flash accounts slash accounts ID it is a, again a collection item with us. So, basically if I see for all collection resources, don't you think that POST method is common? We want to create a new customer, we want an ability to create a new account is it and wherever you see POST method, I see most of them are saying you can see for Portsmouth of customers, maybe the title is customer is it other than that, everything looks in it to see see here for post definition of customer the type is customer then that the response status codes and all are same, right. So basically, even if I see for my slash transactions, this also is Same similar except the type is transactions of customer.

So basically there are a lot of repetitions in this ramble file which is making my ramble file to be very big difficult to read. So whenever there are some lot of similarities in your definition, is it not a good idea to create a template? Yes. So, what my idea is right now to create a template for these resources and to apply the templates, how to create a templates It is nothing but resource types in Revit. So what I will go and do is right now I will for this document, I will create a folder with named resource types right now. Click on plus folder resource types.

Then, under this I want to create a new file And I is now resource type definition. And here I'll give the name as collection collection types okay? Then drag and drop it here inside resource types then copy paste from grammar docs. I have reversed types so copy paste the content of correction not ramble and I'll explain you. Yeah, you can see this is like a template. Now here in this template I am defining post this describing post and question mark what it says.

Optional. Okay. And the interesting thing comes here in ramble. This is a standard. There are some standard keys key words Some operators which are used. So, what is this resource partner?

Let me explain this is a template right resource type definitions like a template will apply this template to some resources. Suppose if I apply this template to slash customers slash customers, what are the first partnering customers put to singular eyes summarizes the function keyword. So, customers pipe to pipe it to synchronize will become customer. So, now this will become an add new customer support if I apply the same template to accounts slash accounts. So the first problem is accounts. I put the single eyes it will become account 30 become add a new account and coming here.

If I apply this to customers, the first pattern is what customers I put a singular eyes in Become customer, upper camel case, it will become customer with capital C. So here to become type is customer. So like that here in this resource type definition I'm using some placeholders, standard placeholders, predefined placeholders in German, and I'm defining a template. Once I have this, how can I reuse this? Let me go here, my main rival. In my main room along the top again I will define something called as resource types. Under that, just follow this document under that.

I will write collection colon explanation include what resource types Oh he says type slash election right? Yep. Now there is no error. Now I want to say that customers is of type collection. So under slash customers I will type here is is Conan What are these stats type this collection right. But once I said this resource is of type collection under post here I'm getting an error What is it saying cannot match payloads with explicit and implicit media types at line number.

So, basically here actually, once I apply the template, these are not required is it same things are applied in the template that I just removed. Now there should be gone if I save it gone. But here we said, apply a template correction template to here and let them go to the post description on the right side. Here the description saying add a new customer type is customer example is applied. That means what? We applied this collection resource type here and we don't need to repeat that.

And I'll go back to summary. Okay now If you see the resource type I said, post this question mark, right? That means it is optional. Now what does it mean? Suppose if I decide for slash customers, I don't want POST method. What I can do is I can just delete it.

I can just delete it. Now you can see observe on the right side, first method is remote. That means, in the template, we can define whatever types we want post put everything. But when we're applying whether we want that particular method or not, can be defined at a playing place. So what if I say of course call on that song? I don't have to define anything else.

If I just say post colon, sorry, I think I'm missing some indentations. Yeah. So right now it appears and the template gets applied, is it okay? Now what I will do is and go back to summary And I want to apply the same thing to slash accounts accounts also I will say that it is of type collection there then again it is showing an error because we don't define again or read is defined inside the resource type definition. So, basically what am I doing? Am I not reducing the size of my ramble by applying the templates wherever possible I will apply the template even for transactions as specify that it is of type collection and I can remove this post.

Similarly, for all number types collection number types all So, number two it means what plus customer slash customer ID right? slash transaction slash transaction ID for all these also there are some repeatable things so I thought I decided to actually write one more resource type for all members. So what I will do is import another file which I have already in the resource types I have member dot ramel Yeah, I'll remove and move this member dot ramel into resource types let's try to see what that member dot ramel yeah it's very big thing. Now here in this member Trammell I'm describing for GET request what will this become if I apply this to slash customers slash customer ID so Spartan Piper to Single eyes. If I apply this to slash customer slash customer ID this become retiree or an customer with a specific customer ID. This will become What?

Get a or n. Customer, by customer ID correct. And what will this become response type. If applied slash customer slash customer ID, it will become customer with capital C. And here you can see it is referencing to customer message. So, actually what I define a template for GET request, patch request and delete request all or optional put request everything for it for now, I'll go to my bank API dot ramel. And here I will specify the first Type member and I use exclamation clewd resource types slash member dot Okay, then oh, yeah, then I would say that slash customer slash customer ID, type. Type is what?

Number it's actually if you see four slash customer slash customer ID I have already defined for get fat and delete. Do I need the others? No. I just remove the description for all. I only have the methods get patched and delete. I don't need anything else.

But I only have the method names. The description is not there if you just observe for slash customer slash customer to get to patch and delete other production my member ramble I have description for get the patch delete as was put putting down question marks it but did you see put here for slash customer slash customer ID. Now it is optional right. So if I want the content which is defined input to be applied here I just have to right click on that cell whatever in the template will be inherited. Right So, that's how we can reuse a template see he can put if I don't want for this particular collection item remember I can select that we can actually make or ramble very small by just Defining the resource types like this. Right?

So now you understood about how to apply resource types. The last one is traits. What are actually traits? Let's let me explain you with an example. Let's assume that for your API somebody gave us a request for GET requests to slash customers and in your database, there are some 10,000 customers. When our GET request comes at retrieve all customers send you right customers.

In the Jason whatever you are responding with will give 10,000 customer it is a good idea. The client may not be interested in all the customers. So normally what we do is we implement pagination is that when our GET request comes first, ask us stammers I view maybe 51 to 50 customer details, but then how to request for 50 hundred? Normally what we do is we define some query parameters like question mark reagent page is equal to two second page and page size is equals to say 50 that means, the basis is 50 and I want second page that means that we have written 51. So, can I say that intonation is required for all collection resources slash customers slash accounts plus transactions for all of them. pagination is required.

So, don't you think that this page and page size Common query parameters to all Yes. So, I can say that the resource slash customers is visible is p g that means what is the behavior actually be here with you can see it three. So, all customers are visible visible the treat which indicates basically a behavior all customers are pleasurable whenever they all customers are patient was that means, query parameters page and page size should be there right. Yes. So, anything behaviors we call it us rights payable is a behavior similarly cacheable whenever I see some responses cacheable How does the client know whether the response ones can be cached or not normally in HTTP. Whenever a client is giving a request server is responding or or has to tell Hey, this is read only data maybe you can cache it.

How does the server tell that the responses can be cacheable by using some standard response headers colors cashable for cache control. So, whenever I say that, some response is cacheable definitely expect headers like cache control expires, etc. Right. Whenever there is some read only data returned, returned, I can say that it is cashable whenever it is something is cashable, the response headers, cache controller and expires. So cashable is also a behavior we call it a trait. Let us see how to define traits.

Okay, but for this example, if I want to define a trait, what I can do is I can create a new file, and I can specify it as a trait, or you can define it. But right now, I don't want to define my own trait, I will show you an existing trait. So I'll go to exchange dependencies, add a new dependency. There is a trait already defined by mule soft called as cashable. I'll search for it. say there is a cacheable right I will select this and add as a dependency to my project.

Right. So it is that now what I will do is I'll select this and I'll say show influence. Yeah, here is a trait. You can see that the definition is a trade definition. Whenever we say something is cashable, I said, there should be response headers for success status code, colors, cache control. And expires.

Yes, this is simple trait. Now how to apply this trait? Very simple. What you can do is you can go to the main Rahman file and here define something called s traits I can see Kashi abou are just for difference as semi casual. And okay let me actually copy the part of this ramble in the extreme so I'll select this icon copy part to clipboard. Then here what I'll do is my casual exclamation include this room Right now I will go to slash customer slash customer ID I want to say that it is cacheable So here I'll say easy cash boom now get request to slash customer slash customer ID since it is cashable let us see here in the description now.

Oh, great. Okay. So I think it will take some time to refresh. I saved it to cache cashier will not phone my cashier when is it? Sorry. Your I will apply is my cash Okay.

Now, let us see, you understood how to use a keyword called ease to apply it right. Okay. Let us see actually played it still not updated it will take some time you can save it yes yep now it is okay. Now let us see for slash customers slash customer ID for 200 status code is there a cache control header added expire cetera and accordingly so that means I have applied my crate so now you understood how to define your own trade and how to play. You are one creating your ramen. So this takes us to the end of how to write reminisce was crushed, we'll discuss most of the common things and ramble.

Hope you'll be able to design your rambles and understand your existing grammars after watching this video, so in the next video, we'll see how How to implement your API's and how to manage your API's. See you next week.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.