Welcome back. This video is in continuation with part one of ramel. So in this video, let us start understanding how to define custom data types. So basically for my API, I won't define my own data types like suppose if I want a customer to have only these fields, I want my customer data type to contain ID. And prefix action if you see after prefix. There's a question mark that means what it is optional, and I want first name, Middle Name, Last Name suffix is optional.
And you can see here address is of type address and address is its own custom data type again, which is different at the bottom. And similarly for account I want account owner to be area of account owner. account owner is defined here on worry, right. So basically, what I want is I want To create my own data types, let us see how to create my own data types in Gremlin. Very simple. What I will do right now is here I am in bank ap ramel I'll click on plus.
First of all, I will create a new folder called as data types. Okay, and inside this I'll click on this and I'll click on plus now, new file. I want to define user right data type. Here I select and I want my ramel filename to be something like custom error. Message dot RAM is the file extension is dot ramel. Let's say create.
You can see that the file is created but outside datatypes selection of selected data which you should have gone inside, but I will drag and drop this data types this ramble file inside data types inside now if we observe this file here after ramble 1.0 it says the file contains a data type definition. If you observe a meal mean Ramadan after Ramadan 1.0 it is not containing anything that means it's a mean ramify and here there is data type in this data type this contains the data type definition and what type of data type I'm defining I want the type as object and I have defined the properties. So what I want is earlier I give property status code and method is it. Same thing here and copy paste. indentation is very important actually. So we have to indent properly to spaces All right.
So I defined my own data type called as custom error message dot ramel which contains two properties status and message. Similarly I can define other data types like customers etc. But to save some time I have already defined them. So I have a zip file in rambled Oxford or Carla's banking data types. So I want to import this so copy this path how to import an existing zip file. Very simple.
I will first of all select the data types. And then I will click on Import. I can import a file unzip, I can select Choose File and here I have banking different types I am importing all the files will be imported. Let's see Oh, I think I imported the wrong zip. So what I will do is select this and delete this actually unselect this and maybe delete this again I imported wrong file so I deleted login and create a new folder called s data types okay so I want to import again select this and import but actually I will import this there type Allah I have imported this banking data types around one I will import this data types right now. Open inputs Okay, so actually all of them came out so I will drag and drop all of them inside data types Okay.
Let's see customer dot Rama see customer dot rammer. Here's our datatype definition. It has properties like customer ID prefix is optional. It's as an equation mind. first name last name suffix soundless and if you see address is affected address and he had to have address Yes. And also I want you to see account account is having a property called as account ID.
You can see here account type is an enum, which has only all these types you understood how to define an enum is it and one important thing is account owner is an area of account owner type here is an another type called account owner. And these are can specify an array. And also can observe that even is a string and we can even specify the regex pattern here as well. Right? This is a very good example of how to define an enum how to define airy how to define a pattern. Right, very nice example.
Select that I have I have all these different types is it Then once I have a type how to refer to these types in my main ramble. Yep. So what I'll do is I will copy paste this document and I'll explain you the main grammar like copy paste let's see how I am referencing. Here I defined a type I defined a key called as types. And here I gave an alias to customer and see here I'm using exclamation include including what data type slash customer so here I'm giving an alias. And then if you see for GET request of customers, the body I am defining application slash Jason type is what?
Customer array. Don't get confused. This is not The name of the amyl file this is the name of the India's support FAQ here, see here are you care is it so here I'm giving an alias and here I'm using the same alias. Here I'm specifying that the response body content will be of type customer array like this. Similarly for 404 type is custom error message and for 406 customers right. And again for post body was the body forget for slash customers type is what I renamed a C writer you see.
Right. So first body is customer and response headers everywhere. What I did is now wherever I was having custom error message properties, I need visit with my customer. Even for here, get ready request to slash customer slash ID the return type will be see whatever I give right so like that I updated the whole document. Now we have given the types but it'd be good if I can give you examples All right. So how to define an example what I can do is simply I can create a new folder examples and under that I want to do a customer example dot ramble I'll create a new file.
Type is got Here is Example your customer example dot Remo you can observe that grandma example here it is named eggs. sample, the type is named example. So what I'll do is right now I have customer example here and go to examples. I'll open this customer example dot Rama copy all then paste. Yeah. So this is how the customer example will look like this example it should be under examples for right I'll just move it.
Okay, now I want to refer to this example here. We'll go to customer Actually, I'll go to the same indentation actually where our properties that I took it here then I'll type example, there is something called an example. Example of this type, and examples. Examples of this type represented as a string, so I can do a direct one example if I can give an example. And what I can do is right now we can use exclamation include include sorry spelling mistake in Claude. What?
Dot dot slash example slash customer example right. So since I have one example I thought I could use example but here I'm getting another named example fragments must be included in exam polls. Actually this is a known issue when design center right now, actually as there is only one example I could even use example. Now I'll say examples. There's a known issue he should have accepted even if I give example. All right, so here example that's okay.
Now that's our can give example it can even import other examples by selecting example I can select inputs. You can select inside examples have a count example. Okay? So I count example it should go to here, sorry. It's a drag and drop. Now you can login modify account or travel to contain example.
That is okay, I'm not doing it. Okay. So I followed the steps given this document I defined that custom type and also examples Now, lastly, I want to add a documentation fragment how to add documentation. So right now what I'll do is I'll create a folder called as documents. Now, documentation maybe I want to add documentation to my ramble. So what I will do is according to this document, I'll write a file with name Acme bank doc dot ramaa.
Create a new file. But now the file type is what? user documentation and the file name I'll give Acme bank. Doc dot Rommel and here you can see the type is documentation item. Actually, the document is item will appear in the documentation of Roman letter we'll see that so what I'll do is again, meramec Doc's have created documentation folder, Acme bank doc dot ramble, I'll copy this content and paste it here. This is a document content which I want to give.
Similarly I want to create one more document Of course I'll move now to documentation folder. We'll create one I want to import one more document in coach. So the file again under documentation I have is Acme bank headline. Right. So again, drag and drop it to documentation. So to documentation rambles, how to use them in the main ramble?
Let us see I have this file where I will copy paste Yep, so I copy paste. So you can see here right now is a key column documentation where I included two documents. So these are what looks like. Now you'll see the impact of documentation later when I generate the nice UI documentation lead. Okay. Now, I'll follow one more document, which I have created.
Ramble part two. Yep. So here, what I want you to understand is, in this API project, I have created custom data types, custom examples, etc. Right? Maybe in our organization, we might be writing multiple API's. And customer travel, the data type customer account and all the I want them to reuse the data types examples.
I want them to be reusable, how to make reusable API fragments. I want this data types and examples to be published as a separate asset, so that they can be reused across APA projects. How to do that. Let us see. So again, I'll go back to my design center. Now I'll create earlier I selected create API specification.
Now I'll click on Create API fragment. I'll say my banking types as a fragment and what are the current thing it contains data types this fragment contains data type definitions create a fragment project will be created right now. Okay. Now no I don't want to type in each and everything I want to import import. I have a file already given inside my ramel doc there's banking data types zip file, I'll open that import. Let us see what is there in that zip after important.
Yep, here you can see data types and examples. Whatever I want to reuse, is it customer dot ramify. See? It's having the examples included right. So Other data types now I want these to be reusable. So what are reusable assets are there we already understand.
We understood that we can publish them to exchange how to publish any asset to exchange. I just have to click on Publish to exchange. And what's the name of this fragment? I'll say Siva banking types. I said Watson from Watson, it's taken by default publish. So it's publishing my Siva banking tied to API.
Exchange. So if I want to see the exchange, I can click on this link. It will show me the server banking types in the exchange Moses right now I'll go back to asset list. Here you can see see what banking touches it and this is an asset from the to learn and if you click on this Provided by mule soft you will see the assets provided by mule soft right now published by wetland These are only a set. Okay, now how to reuse this asset in exchange in my one other API project. Let us go to the designer once more.
Go to design center again, go to my original bank API. Okay. Here you can see that there are two links on the left side first one is files and the second one is exchange dependency. I want something in Excel to be added as a dependency to my project. So click on plus add dependencies and I'll search for See? And Yep, did see that.
My APA fragment which I published here is appearing, yes, I'll add one dependence. Okay. Now I want this dependency to be shown files. I clicked on it, and I'll select this show in files. See, exchange modules are shown in phase, my banking types 1.0 point zero data types. So now, I want this customer to travel to be used.
What I'll do is I'll click on this copy part to clipboard. Then I'll go to my main file. here instead of including the local ones, I'll delete this and I'll paste. See, I'm actually including the ones in exchange modules. Right? Now can I go to data types here and delete my customer data model?
It is no more required locally because it's pointing to the exchange dependency. Yes, I'm deleting the custom model. Right. So like that, what I can do is I can actually delete my whole examples folder and database folder. And I can point everything to exchange dependency. Now you understood how to actually reuse API fragment, how to create API fragments, and also how to reuse the API fragments.
So this we haven't ever done before this document. Yep. So Now let us publish this ramble APA specification. Oops, sorry, this is already done. So it is done. So right now, actually what we want to publish the APA specification itself to exchange.
Okay. After we have published the APA fragment, if you want to publish API specification also to exchanges, click on this. Yeah, my bank API. I'm publishing this also to exchange the words AP versus the one publish example, it will be published to exchange done. Now, if I go to my exchange, and if I refresh, I should see my bank API also. Nice.
So now you understood how to publish. So if I go to this my bank API. Actually, whatever asserts populist in the exchange is local, local to the organization, the customers outside of your organization cannot view the assets in exchange, how to make the assets in your exchange, the API is near exchange to be visible to outside of your organization, what you can do is you can share this API to a public portal. So I can click on this link at the public portal, which version version one ship. So now, this will be published, public portal done, how to see the portal. Go back to the asset list of your excellence.
Here is a link to public portal if I click on it. Now it will take me to the public portal URL where I can see this URL public. portal URL. You can actually share it with somebody and whoever has this. They don't need to be part of your organization, they'll be able to view your API's is that. So here is the summary.
This API, you can clearly see it, right. So one beautiful thing about designer is in designer, we have something called mocking so is on the right side. Actually, we are still in the design phase of our API. We want to get feedback from our stakeholders about the API design. But we didn't implement this API how to get the feedback. So what I can do is I can switch on the mocking service.
Once I switch on the mocking service, you can see that base URI is given Third, this is Margaret, this URL, let me take this UI and using my postman, I will try to give a request. Okay, just wait until postman starts. Yep. So I'll try to give a request to this mock up URL slash customers get request. Hey, I got How did I get it actually? How is it mocking?
Is it the same thing which I gave in my example? Yes, I am getting the response from the mock could URL. The mock server is not doing much it is just giving the response whatever I specified in the example of my customer data type, is that so basically, once I mock my URL, and if I publish it, somebody in my public portal who is seeing My APN public portal, they'll be able to test try out the API as well. Right? This is my portal. And actually right now the base URL is not different, because when I was publishing it, the base URI was not defined.
Actually, what I could have done is out after mocking I should have published to my portal that the best you could have been available. And somebody who is seeing this in portal will be able to try out by clicking on get and click on this one, send a request. I got it got upgraded automatically, right? slash customers. Yep, I got it. See, after mocking, I'll be able to send a mock request and I'll be able to get it on my portal as well.
So somebody who sees this API on the portal, they'll be able to try and they feel as if they're getting the real response. So now we understood about how to publish your assets to exchange and also to Portland how to share your API's to other customers using portals. I'll see you a few more. I'll see few more things in next week. See you next week.