hello everyone this is prem kumar in this video i'm going to explain you how to create a new service rest in pega i'm going to use the get method in this tutorial in the last video we already talked about some of the basics of the rest service so i hope you already know about this uri pattern the query strings all those resource paths now let's get started with the simple request and response which we will be using in this tutorial if you look at this picture there you can see at the top it has a simple request since i'm using the get method i don't have any kind of body message and the customer id it is getting passed into the resource url itself and here my business requirement is i need to give the fraud details back when i get the customer id as input we already know that clients application is the source of record the source of truth for this fraudulent details so we store those details into our own data type or our own database table so external applications they may be interested in those data so here in this situation external application is definitely interested in our data so that is why we are going to create our own service request exposing this fraud details so we made the customer id as the input and it is going to come in the resource param i don't have a query string i just made it as the resource param so this is going to be my request for the response i can just give them all the attributes that i store into the data type the fraudulent check if i look at the data type i see i store only four attributes these are the four attributes which we are responsible which the client's application is responsible that is on fraud type the customer id the customer name and the policy type so i can provide only these four details so definitely i can have it inside the response object the response object what i meant is json every data is going to be under one object at least one object as you can see the curly braces so it represents an object so that i can consider it as a response object and under the response object i can have the four fields directly into the response otherwise i can also have some more detailed or embedded objects into my response in the other side you see there is a complete response object and under the response object we have fraud type we have customer id then we embed another object that is on customer details that holds the customer name and then we hold another array which holds the policy details so i can give what are the types of policy that are related to this customer so this is very simple example just i wanted to show you both ways i want to implement both this scenario to let you know that how to create a page how to create a page list how to create all the integration classes for such json structure so at the end what we are going to do is we get a customer ideas input we are going to give them the fraud details back so how to start with this service rest there are five simple steps which you can define the first thing is you have to define unto which layer you want to create this service rest we already know our clients application structure we have the organizational layer we don't have any division or unit layer we directly have our application layer so the integrations can go into two place either you can go into the organizational integration or it can go into the application integration i see this fraud details is more related to the client's application it is not more related to the organizational so i am going to create the integration layer into the application layer so my int layer is going to be a life hyphen climb sap hyphen gint it's not going to be a life hint it's going to be a life climbs up in so that decision i already made the next decision is create the integration layers you have to create the integration class layer you have to create the integration data layer and we don't have a wizard it's it's really pity till 8.7 we don't have a wizard for this service rest so you have to create everything manually you have to manually create the class you have to manually create the properties and if you have a very big structure it's going to be really a big problem or not a problem you have to do a lot of manual stuff you have to manually create a lot of properties for that but for connect rest we do have the wizard so no problem with the connectors only the problem or some kind of crazy work for this service rest so once you define the data model you can either go with creating the service rest but i would recommend you to just create the service activity because you have all the properties and mostly for this get method you can directly go with the service activity because the request is going to be like a parameterized one so you can very well test the data you can create your service activity that can accept the input parameter that can do all the processing in our scenario we have to get the fraudulent details and then map it into the response that's what the service activity need to do in the next video we will also talk about the error handling but for now let's create a very simple activity that we will do and the fourth step will be deciding on the service package we already saw in the before video we know how to use a service package and for climbs up we already created a service package to include the service soap integration so we are going to reuse the same service package we are not going to create a dedicated service package here so for this service rest i'm going to make creation of service package as optional or i'm not going to create i'm going to use the existing service package and the final step the main important step we have to manually create the service restroom so these are the five steps which we will be doing and i will be starting with the second step let's get started so here i have logged in into the destination studio and currently i opened the app explorer as you can see the class a life climbs app work now i'm going to replace the work with the hint because i'm going to create the integration classes so it's going to be a live climb sub hint so my main integration class i am going to name it as fraud details api so let's straight away create a new class here and i want to create it into a dedicated rule set so to do that i'm going to create a new rule set but i already have a rule set that got created during the last video for the service so so i'm going to use the same rule set because at the end it's all about the services which is getting exposed by the clients app i could decide to have my own rule set for this service otherwise i can go to the common rule set which hold all the services for now i'll just go with the application related rule set the service rule set so no problem i'm not going to create any rule set only thing i am going to change into service clients app rule set now do a create and open so this is the first class which we are creating finish up the configuration okay now looking at my response data model what i can really do is here i can create a property definitely i have to create a page property that is going to hold all this response object so i will create whatever property i want i am just going to name it as fraud details response under this class and the class of the page i can just reuse the fraud details data class i don't want to again create an integration class and then define all the four properties under the integration class and later i do the mapping or copy the data from data to int instead i can directly use the data layer first let me show you how to do that i'm going to do a refresh here and this is going to hold the main property the response property so i'm going to create a data model property so this is going to be my response property create it and here change it to a single page the class definition is the key what i'm saying is i'm going to use client sap data fraud watch list i'm not creating any int layer here the main reason is i defined the records attributes and the properties also looks the same like the same type of property i have it into my data layer and the same property is there into the response json so all i can do is i can just reuse it i don't have any kind of extra property so i can just reuse it and save it so that the response data can be mapped directly from here otherwise what you can do is you can say a life claims app int you can create another class saying that fraud details api underscore response or you can just say fraud details even and then you can create all these four properties under those class that is possible but i feel that is redundant because i am going to reuse it always pega recommends us to reuse it we can always reuse it there is no problem that int cannot refer data layer technically even if you arrange your application stack data is always going to be at the bottom layer and then you build int over the data layer so definitely int can always access this data layer so for this scenario my response is already done now let's look at the another sample if you look at this sample what you find here is you need to create some other structure you need to create the customer details you need to create the policy details so for this what i have to do is i cannot reuse the same property the same response property because this response property is already pointing to the data layer now to do that what i'm going to do is first i'm going to define an integration class another integration class that can hold the object in the previous example this is the class that is holding the entire object the response object but there is a prop page property and that is the class so that is holding the entire object but in the second sample we have to use a different class so first let's create another class you don't want to always extend from apa you can always create it at the top layer itself so you can follow with me and then just create a new class so here i am creating the class as just fraud details fraud details api is the main class and fraud details is going to hold all the objects that are part of the response and then just complete this now that we have completed creating the two class and these two class are already sufficient now we can create another property here it's going to be the response property again here i'm not using any fraud data but instead i'm going to use the integration so now then we created two class and this property the data model property there are two properties one for first sample and the second for the second response sample the first response sample it is pointing to the data layer so we got all the properties but for the second response we have to now define the property so all the property should be defined under the fraud details so here i will start creating four properties now now if you look at here i created two properties customer details and policy details customer details is going to be a page policy details is going to be a page list as you can see from the sample now the classes i can again create integration class and create properties but again i'm going to reuse it just to show you i created this in the integration but really ideally i'll never try to create all these integration properties and integration layers redundantly i just wanted to reuse every time so what i'm going to do here is i'm going to just use the customer details class so it's going to be a life data customer and the other is going to be a life data policy now if i do a refresh here you should see that under fraud details we have all the properties that are part of the sample too the customer id is there fraud type is there customer details is there under customer detail we can reference whatever property we want so we have the full name here i should actually have it as customer name but let's see how we are going to reuse it for now i'll just stick with that i have the property there and similarly for policy details i have the policy type so in the sample one i have reused the fraud data type and in the sample two i have reused the customer details and policy details but still i created one more integration layer now defining our integration layer the class and properties are done now let's go to the next step of creating the service activity let's start with that using the create menu we know where to create activity technical activity and from here i'm going to say get fraud details and this activity is a service activity so definitely you should be on the main int layer so i'm going to use it here because i'm going to create my service soap onto this layer and the activity should be accessible from the service so it means the activity should be accessible for this class so definitely it is going to be on the fraud details api class so my activity create form is here i'm going to create an open let's see what we can do in this activity as i mentioned earlier i'm not going to concentrate on implementing the error handling in this video in the next video we will implement the error handling for now we will just stick with the positive scenario expecting that for the input customer id we always have the fraudulent details into our database so the parameter i am going to say parameter as customer id i'll just say like this customer id this is fine and then this is coming as an input now what i have to do is just opening the data type where i hold all the fraud watch list and here i already have a data page as you can see here the usage i have the underscore fraud watch list let me first open the data page so that is going to open a single instance here now if you go to fraud watch list and check the results i want to get it for the customer id prime kumar now if i go to this data page and if i run it it is going to get me all the details so if i just say frame kumar here do a run let's see i get all my details i get my customer id customer name fraud type and policy number these four are the necessary thing which i need to map okay now i will use this data page into the activity and get the response into my response properties so what i'm going to do here is i go to the activity and here i already defined the parameter now for the data page let's check the parameter it is on customer id so i have to get this customer id set since it is kind of case sensitive i'm going to use first parameter param dot customer id i'm going to get the input parameter here my input parameter is defined like this i could have done one more thing what i could have done is i could have said this activity parameter the same thing so i don't want to have the first step so what i'm going to do i'm just going to update this into the right parameter so the same parameter will be used by the data page so i don't want to manually set it into a different parameter name just a case mismatch is there so what i can do is i just updated this activity parameter so in the first step i can directly reference the data page the data page is d underscore fraud watch list and then in the property set i can do a property set to the response so my response property will be primary so to get the context of this integration and then i'm going to set it to the first response for the sample one so i will say dot customer id that will be equal to from here customer id now i will map all the four properties so here i have mapped all the four properties and note that i am using primary because i want to set these data into the primary context into the response property that is why i use primary also the step page because the same page took the context of data page i have to use this primary here so in the primary i set all these now when i use this activity into the service rest in the primary page in the response i will have all the details always remember whenever you use a step page make sure you add it here i have to use the step page as well as the class for the step page so i'm just copying it here and specify it into the pages and class now all your errors should be gone okay now the main thing is why i ask you to first create an activity is you can very well test it manually before you create your service rest individually you can always test it so i'm going to test my data let's check if i get the right data i'm going to run it and then let me check in the clipboard because i run it in the primary page it should be under this run record primary page under the fraud details response i see all the details that are currently existing into the data type so this service activity is perfectly working for an valid input or an existing input now the next step is we have to define a service package which we are going to use already so let's go to the final step of defining the service rest we have to create it manually okay let's start with that let's go with the create menu integration services service rest and then you can provide the name so this is going to give the fraud details so i'm just going to give the name as fraud details so this is going to be my service name the package is going to be clients app services and then the service version i'm going to name it as v1 so always go with this v1 versioning that will also really help you if you want to upgrade it to a different version you can go with v2 v3 and things and then the uri template this is the key thing if you look at this request you will find that what should be the uri template we saw that the service package name is there version is there here just make sure that i'm going to use the same fraud details here let's see how the url template gets formed i'm going to say like this and then i'm going to provide the customer id so this should be fine and pega generates an unique id do you know why pega generates this unique id because under different url template you can have different pega services what i meant is if i have only the fraud details i can create a separate service rest for that if i have fraud details customer id and new i can create a separate service address so by this way packer can uniquely identify for each of the url template it identifies and it creates an unique id that is why you see some kind of junk character if you want to build your uri you can also build like this when you use this option you have two options either to use it as a literal literal is like it's not a variable the opposite of variable is literal and if it is a variable you can very well choose it so that customer id can be dynamically passed definitely customer id is going to be the variable that is why i specified it as variable now do a summit so this step the create form is the one of the key thing whenever you define the service rest now let's do create and open let's check how the url get formed as you can see the localhost pr web this is the service package name this is the version name and this is the resource uri the service name didn't come into the url that is also one of the key thing so you have to specify the real name into the uri pattern so fraud details is here and then customer id is here as you can already see customer id is already mapped to a parameter customer id if you really want you can change it if you want to map it to some property you can very well do it so this block the resource properties block is pre-filled when you filled the create form but only thing which you can adjust is on this place as well as the resource as you can see the resource definitely we have to adjust because look at the class it used the app explorer default class so i have to change it into the int and then the new class which we created so the new class is on fraud details api so this will be my resource primary class the primary class should be on the class on which you are going to create your service rest as well as all those main properties the request response properties those should be there into that class so that's why i'm going to use this class and then my parameter i am going to leave it like that processing option this looks exactly same to what we saw in the previous videos for the service so so we can decide when to end the requester this is useful only when the service package is marked as stateful and if you want your service not to be stateful then you can enable this option so that even though if your service is part of the service package that is configured as stateful you will end the request you will not maintain the session so if you want you can really do it method is read only usually i don't consider all these read only in the connect and so so you can just leave it out enable service sla with fallback activity the same configuration which we saw before you can define an sla for your service and let's say here we define an sla of 500 milliseconds so if your service activity exits this time then you can perform a different fallback activity you can do whatever you want using the fallback activity and then you have the lightweight clipboard mode you can enable the lightweight clipboard mode but have a warning that the service will be executed using the lightweight clipboard mode just to improve the performance but it does not support the full clipboard api features so don't use it really if you have a lot of performance issue then you can give a trial and error check this option and then check if everything is working perfectly fine otherwise you don't need to enable this option you can also control this pair environment for example the lower environment you don't want to enable it and if you want to enable only for the higher environment you can very well do it you can use this application settings and that you can configure those options now i'm going back here here you can also set the execution mode again this is exactly similar to what we saw in the service so you can execute synchronously sequentially it means you can also execute on a queue on error so if there is some kind of error only then you queue it and give the queue item id so that the consumer can come back again with the queue item id the third option is you can asynchronously queue for execution if you are using the queue options 100 you have to use this request processor and then you can also control the monitoring as well as you see what is the service package that is defined so this is exactly the same which we saw during the service so so that is why i'm just rushing little bit i don't want to explain the same thing again and again now let's go to the method tab so this is the main tab and this video is dedicated only for the get method so i will concentrate only on the gate method let's expand the get method here you can define two kind of service thing one you can use via activity second we can use via automation i have never used automation in my life so i'm going to use only with the activity we already created the activity so let's use the activity here get fraud details and you see the parameter customer id so we have to pass the customer id and we already know where we get the customer id we have this into param dot customer id so let's get this and pass it here value of param.customerid which we get from the url will be passed to the activity and we already tested the activity if we pass the right customer id we always get the right response so this should perfectly work now only thing which i need to concentrate is on the request and response how i'm going to get the records how i'm going to get the response request i can leave it empty because i get it into the resource uri i don't have any header i don't have any kind of kodi string as you can see already the resource path is read only and it is mapping to customer id i don't have any kind of query string here so i can just leave it out empty it is not even mandatory then you go to the response and in the response you can define what to send back for the first sample we already know what to send back we have to send back all the four details the object the fraudulent details object that is into the response property so what i can do here is first let me configure the message data map from you get different option you can send a constant response you can use it from the clipboard you can use it from json you can use it from different streams mostly we will use either clipboard or json let's look at what is the main difference between this clipboard or json first let me try with clipboard so in clipboard if i give map fraud details from response the only thing which changed quickly is application.xml it is changing the response type into xml instead of json ideally the consumers may be expecting the response into the json structure if they can really handle even if the response is of xml because rust always support both the xml and json we can very well do it there is no issue with that also if the consumer is a pega application they can also very well handle this on their own so there won't be any big issue they don't want to develop some kind of specific code to handle this application xml but to be on the safer side you can always use the json here if you use the json definitely you have to provide here a page property or an object property you know why because json always starts with an object so definitely you should use some object property and object property in pega it can be either page list or page so definitely you have to use a page list or page and here i'm going to use the response that is a page and then you get three options use fast forwarding what does use fast forwarding does is it will copy all the details that are into the fraud details response the page into the json structure it just quickly does it and really it improves the performance or you can use the use json data transformation if you use it then it will ask you to provide a json data transform json data transform you can create it on your own when you create a data transform you have an option to use either json or you go with the normal way you can use the json data transform and that also fast forward maybe that improves the performance you can very well use that option or you can just stick with the legacy method normally how pega does with the engine code you can stick with that so what i am going to do is i am going to use fast processing you know why because all my properties which i mapped from the service activity needs to be sent there is no kind of issue i don't have any kind of extra property there so i can just use the fast processing and here you can add multiple response condition that we will see during the error handling but just letting you know that you can add multiple response conditions and based on the condition you can have multiple response data and all the error handling you are going to handle to only at this place so these are the main configuration on the get method if you go to post method you will find that even for the request you will have a body so that is main difference between the gate and pose we already saw during the basics video get message they don't have a request body whereas posts are put they have the request body and of course delete they don't have the request body okay now we have created our service rest let's save it and see if there is some kind of error it perfectly saved so there is no error the service rest is ready to get tested let's test it first manually let's run git method and i'm going to try for my id and i'm using the current requester context it means it runs under my contacts so authentication those things will not be a problem if i do execute then let's check i get the valid response i get the policy number fraud type customer id customer name everything is perfectly there from the data type so this service rest is working as expected now let's do one more testing usually whenever i use service rest i always like to test with the postman postman is like a very tool i am very fond of the tool and i will also like you to use the tool that is really good for testing all your services especially the rest services so here i have launched my postman and from this place i can make a get records to my local server first let me go to the destiny studio and get the service url this is going to be http remember it's a http so definitely in the service package i need to disable the tls ssl option there maybe first let me test and see how it behaves and the customer id i'm going to test for prem kumar let me do a send for not one unauthorized error because definitely i didn't use any kind of authentication first let me provide the authorization i'm going to use a basic authentication here username password so i can just provide my username password always don't use your username password have a dedicated username and password for all the service related authentications now do a send let's check i didn't get any response back but at least i got 200 so i'm able to hit but the thing is like i didn't get any response that is bit strange so it seems something is going wrong now i will quickly show you how to debug a service rest i actually saved it for the error handling but let me quickly show you go to the destination studio and from here you can go to actions and do a trace now you can trace your service rest whoever hits it whatever consumer hits it you can always trace your service rest now now let me hit it again from the postman into a send i'm again getting an empty okay let me check the tracer i got an error here as you can see there is any error so it's easy we found out let's check prem kumar and the parameter is curly braces is coming in because i didn't remove the curly bases definitely in the url the curly braces should be removed so somehow when i copied human error remove this frame kumar and send it you will get the response again an error i'm not sure what error is this time let me again trace it i always like error so let's see what's this time do send so it's empty let's go to tracer and again error let's check this time the value looks good prim kumar but let me check from the sql query there is a space one big learning i learned is never copy paste a very simple thing i could have typed it here i see there is an enter key okay so i can just remove that now if i send 100 it's coming it came the result came so we have successfully tested we have created our own service rest so we gave our input and we successfully tested this service rest it is giving us the result so it uses the service activity and process the result so i hope you find this video informative in the next video i'm not going to explain about error handling but i am going to start with the post method only after completing the post method by creating a new service rest we will start with the error handling of both the get as well as post method see you in the next video