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.18
List Price:  €95.97
You save:  €28.79
£55.86
List Price:  £79.80
You save:  £23.94
CA$97.87
List Price:  CA$139.82
You save:  CA$41.95
A$107.62
List Price:  A$153.75
You save:  A$46.13
S$94.24
List Price:  S$134.64
You save:  S$40.39
HK$544.83
List Price:  HK$778.36
You save:  HK$233.53
CHF 62.54
List Price:  CHF 89.34
You save:  CHF 26.80
NOK kr774.97
List Price:  NOK kr1,107.14
You save:  NOK kr332.17
DKK kr501
List Price:  DKK kr715.75
You save:  DKK kr214.74
NZ$119.95
List Price:  NZ$171.37
You save:  NZ$51.41
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,361.58
List Price:  ৳11,945.63
You save:  ৳3,584.04
₹5,909.84
List Price:  ₹8,442.99
You save:  ₹2,533.15
RM312.71
List Price:  RM446.75
You save:  RM134.04
₦118,484.88
List Price:  ₦169,271.38
You save:  ₦50,786.49
₨19,443.22
List Price:  ₨27,777.22
You save:  ₨8,334
฿2,412.28
List Price:  ฿3,446.26
You save:  ฿1,033.98
₺2,418.32
List Price:  ₺3,454.90
You save:  ₺1,036.57
B$406.01
List Price:  B$580.04
You save:  B$174.03
R1,267.89
List Price:  R1,811.35
You save:  R543.45
Лв131.37
List Price:  Лв187.69
You save:  Лв56.31
₩98,301.65
List Price:  ₩140,436.95
You save:  ₩42,135.30
₪259.10
List Price:  ₪370.16
You save:  ₪111.06
₱4,125.14
List Price:  ₱5,893.31
You save:  ₱1,768.17
¥10,832.35
List Price:  ¥15,475.45
You save:  ¥4,643.10
MX$1,429.79
List Price:  MX$2,042.64
You save:  MX$612.85
QR255.18
List Price:  QR364.56
You save:  QR109.38
P956.90
List Price:  P1,367.06
You save:  P410.16
KSh9,061.51
List Price:  KSh12,945.58
You save:  KSh3,884.06
E£3,475.01
List Price:  E£4,964.52
You save:  E£1,489.50
ብር8,566
List Price:  ብር12,237.67
You save:  ብር3,671.66
Kz63,900.87
List Price:  Kz91,290.87
You save:  Kz27,390
CLP$69,057.73
List Price:  CLP$98,658.13
You save:  CLP$29,600.40
CN¥506.93
List Price:  CN¥724.22
You save:  CN¥217.29
RD$4,217.06
List Price:  RD$6,024.63
You save:  RD$1,807.57
DA9,397.90
List Price:  DA13,426.15
You save:  DA4,028.25
FJ$159.29
List Price:  FJ$227.57
You save:  FJ$68.27
Q540.13
List Price:  Q771.64
You save:  Q231.51
GY$14,638.82
List Price:  GY$20,913.50
You save:  GY$6,274.67
ISK kr9,776.20
List Price:  ISK kr13,966.60
You save:  ISK kr4,190.40
DH703.91
List Price:  DH1,005.63
You save:  DH301.72
L1,275.33
List Price:  L1,821.98
You save:  L546.64
ден4,132.76
List Price:  ден5,904.20
You save:  ден1,771.43
MOP$561.01
List Price:  MOP$801.48
You save:  MOP$240.46
N$1,268.91
List Price:  N$1,812.81
You save:  N$543.90
C$2,574.70
List Price:  C$3,678.31
You save:  C$1,103.60
रु9,449.77
List Price:  रु13,500.25
You save:  रु4,050.48
S/265.32
List Price:  S/379.05
You save:  S/113.72
K281.71
List Price:  K402.47
You save:  K120.75
SAR262.77
List Price:  SAR375.40
You save:  SAR112.63
ZK1,934.92
List Price:  ZK2,764.29
You save:  ZK829.37
L334.42
List Price:  L477.77
You save:  L143.34
Kč1,702.59
List Price:  Kč2,432.37
You save:  Kč729.78
Ft27,646.05
List Price:  Ft39,496.05
You save:  Ft11,850
SEK kr772.42
List Price:  SEK kr1,103.50
You save:  SEK kr331.08
ARS$70,259.44
List Price:  ARS$100,374.93
You save:  ARS$30,115.49
Bs483.50
List Price:  Bs690.75
You save:  Bs207.24
COP$307,238.59
List Price:  COP$438,931.09
You save:  COP$131,692.49
₡35,641.51
List Price:  ₡50,918.63
You save:  ₡15,277.11
L1,768.23
List Price:  L2,526.16
You save:  L757.92
₲546,248.87
List Price:  ₲780,388.98
You save:  ₲234,140.10
$U2,983.14
List Price:  $U4,261.82
You save:  $U1,278.67
zł291.40
List Price:  zł416.31
You save:  zł124.90
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.