Open server module |
Let’s start by opening our Server Module. It’s called TutorialPublish unless you gave it a different name. |
Showing source tab, click API definition tab |
Here we are in the source tab. Since we’re not writing any code in this tutorial, let’s switch over to the API Definition tab. |
Click Add |
To define a path, click the Add button and choose path. The red arrow indicates we have one or more errors in our API definition. |
Click red arrow |
When we click on the arrow, we see the path requires at least one segment. Segments are like subdirectories of the Path. Segments are defined in the Path Name. |
Double click on path |
Let’s specify the Path Name as /Contacts. (/Contact for other video) |
Click red arrow |
Let’s click on the red arrow one more time to verify that the Path Error has gone away. Server routines have the executable code to handle Operations like Get and Put. |
Expand Operations Click on
Getxx |
Let’s expand “Operations” and click “Getxx” to show its details. Change the name to GetContacts and leave the default verb as Get. |
Click the … Select GetContacts. |
Next, we need to select the GetContacts Server Routine. Since GetContacts will return a list of Contacts from the table named xContacts, we need to define a parameter that will hold the search criteria to access the table. |
Click on Path Click add button and choose parameter |
Let’s create the parameter now. First, we set the name to SearchString. And second, we set the location. In the Handle One Resource tutorial, we used a parameter in the Path. For this example, we need to pass it via a query string. |
Click red arrow |
As we can see under the red arrow, the parameter has been defined but not described. |
Expand SearchString. Click schema object. |
To describe it, we simply expand SearchString and click on schema object to view its details. In the description, type in something like String to search First and Last Name of Contacts… and set the type to String. The GetContacts operation is now complete. Next, we need a PutContacts operation. |
Click on /Contacts path Click add button Click Updatexx |
We just add a new operation… Set the name to PutContacts. Make sure the verb to set to Put. And select the PutContacts server routine. |
|
Since PutContacts is going to receive a list/array containing id, first name and last name… and then updated in database table xContacts… |
Click on Schema under Components |
We must describe the requested information in a Schema Type, which we can then reference in the PutContacts request Media Type. |
Click the add button |
To do this, we add a Type. Set the name to PutContactsRequest. Set the description to Contact Request Definition. And we’ll set the type to Array because the requested information is a going to be a list. |
Click red arrow |
According the red arrow, we must define the items of our array, which are contact id (used to access xContacts), first name, and last name. |
Click the add button |
So, we add an new item and set the description to something like Request Object Definition. |
Click red arrow |
As you can see, the next step is to create the object properties for contact id, first name and last name, so let’s add them now. |
Click the add button |
Our first property will be called ContactId and we’ll set the description to Contact Identification… and the type to field. Again, our field names must exist in the repository, so we can hit F8 to show the repository view and go find the fields on the xContacts table. Here is our ID field. And these are the first name and last name fields we will use for the other properties. Let’s right-mouse click on xContactIdentification to Copy the name. When we double click on the Schema object, we can see its details again and paste field name.
|
Click on the item Click the add button |
We must refocus on the item before adding the next property. Set the name to FirstName… Set the description to First Name of Contact… And set the type to field. Instead of using F8 to find the field name, we’ll just manually type in xContactFirstName. |
Click on the item Click the add button |
And again, we must refocus on the item before adding the last property. Set the name to LastName… Set the description to Last Name of Contact… Set the type to field… And type in the field name xContactLastName. |
|
At this point we have finished describing the schema we expect in the PutContacts request… Now let’s link them together. |
Expand PutContacts Expand Request Expand Media Types Expand application/json Click on Schema Object |
To do that, we expand PutContacts… Request… Media Types… application/json and click on Schema Object. Here we can set the Type to Reference… And set the reference name to PutContactsRequest. |
Save |
Just save the server module and we’re done. |
This completes the API definition.
You should proceed to do the Get a List and Put a List items too. It will show you the code required for the – currently empty – server routines.