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
€67.35
List Price:  €96.21
You save:  €28.86
£55.83
List Price:  £79.77
You save:  £23.93
CA$100.76
List Price:  CA$143.95
You save:  CA$43.19
A$112.23
List Price:  A$160.33
You save:  A$48.10
S$95.14
List Price:  S$135.93
You save:  S$40.78
HK$543.62
List Price:  HK$776.63
You save:  HK$233.01
CHF 63.04
List Price:  CHF 90.06
You save:  CHF 27.02
NOK kr797.48
List Price:  NOK kr1,139.30
You save:  NOK kr341.82
DKK kr502.49
List Price:  DKK kr717.87
You save:  DKK kr215.38
NZ$124.10
List Price:  NZ$177.29
You save:  NZ$53.19
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.18
৳8,361.55
List Price:  ৳11,945.58
You save:  ৳3,584.03
₹5,962.79
List Price:  ₹8,518.63
You save:  ₹2,555.84
RM314.04
List Price:  RM448.65
You save:  RM134.61
₦108,335.42
List Price:  ₦154,771.52
You save:  ₦46,436.10
₨19,495.71
List Price:  ₨27,852.21
You save:  ₨8,356.49
฿2,390.81
List Price:  ฿3,415.60
You save:  ฿1,024.78
₺2,467.44
List Price:  ₺3,525.07
You save:  ₺1,057.62
B$434.14
List Price:  B$620.23
You save:  B$186.09
R1,296.68
List Price:  R1,852.48
You save:  R555.80
Лв131.68
List Price:  Лв188.12
You save:  Лв56.44
₩102,198.93
List Price:  ₩146,004.73
You save:  ₩43,805.79
₪256.56
List Price:  ₪366.53
You save:  ₪109.97
₱4,090.81
List Price:  ₱5,844.26
You save:  ₱1,753.45
¥10,994.99
List Price:  ¥15,707.80
You save:  ¥4,712.81
MX$1,408.98
List Price:  MX$2,012.91
You save:  MX$603.93
QR255.09
List Price:  QR364.43
You save:  QR109.34
P967.82
List Price:  P1,382.66
You save:  P414.84
KSh9,046.20
List Price:  KSh12,923.70
You save:  KSh3,877.50
E£3,562.49
List Price:  E£5,089.49
You save:  E£1,527
ብር8,907.19
List Price:  ብር12,725.10
You save:  ብር3,817.91
Kz63,830.88
List Price:  Kz91,190.88
You save:  Kz27,360
CLP$69,323.69
List Price:  CLP$99,038.09
You save:  CLP$29,714.40
CN¥510.80
List Price:  CN¥729.75
You save:  CN¥218.94
RD$4,245.36
List Price:  RD$6,065.06
You save:  RD$1,819.70
DA9,465.07
List Price:  DA13,522.10
You save:  DA4,057.03
FJ$162.39
List Price:  FJ$232
You save:  FJ$69.60
Q539.11
List Price:  Q770.19
You save:  Q231.08
GY$14,638.77
List Price:  GY$20,913.42
You save:  GY$6,274.65
ISK kr9,772.70
List Price:  ISK kr13,961.60
You save:  ISK kr4,188.90
DH703.98
List Price:  DH1,005.73
You save:  DH301.75
L1,291.33
List Price:  L1,844.84
You save:  L553.50
ден4,143.97
List Price:  ден5,920.21
You save:  ден1,776.24
MOP$559.97
List Price:  MOP$800
You save:  MOP$240.02
N$1,289.45
List Price:  N$1,842.15
You save:  N$552.70
C$2,574.80
List Price:  C$3,678.44
You save:  C$1,103.64
रु9,534.71
List Price:  रु13,621.60
You save:  रु4,086.89
S/260.99
List Price:  S/372.86
You save:  S/111.86
K283.85
List Price:  K405.52
You save:  K121.66
SAR262.91
List Price:  SAR375.60
You save:  SAR112.69
ZK1,936.45
List Price:  ZK2,766.47
You save:  ZK830.02
L335.12
List Price:  L478.77
You save:  L143.64
Kč1,694.03
List Price:  Kč2,420.15
You save:  Kč726.12
Ft27,771.44
List Price:  Ft39,675.18
You save:  Ft11,903.74
SEK kr774.38
List Price:  SEK kr1,106.30
You save:  SEK kr331.92
ARS$71,792.58
List Price:  ARS$102,565.23
You save:  ARS$30,772.64
Bs484.55
List Price:  Bs692.24
You save:  Bs207.69
COP$307,165.41
List Price:  COP$438,826.54
You save:  COP$131,661.12
₡35,530.54
List Price:  ₡50,760.09
You save:  ₡15,229.55
L1,777.33
List Price:  L2,539.15
You save:  L761.82
₲546,250
List Price:  ₲780,390.60
You save:  ₲234,140.59
$U3,115.91
List Price:  $U4,451.49
You save:  $U1,335.58
zł287.82
List Price:  zł411.19
You save:  zł123.37
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.