Defining Resources

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Defining Resources

Previous pageReturn to chapter overviewNext page

Now that we have some basic data types defined we can start building the API that uses them.

Defining the TaxFilingObject resource

1. The resourceAPI has a baseURI set to Change this to
2. In the resourceAPI, you should see a generated objectResource named TaxBlasterObject, bound to the data type TaxFiling. Expand this (if it is still folded) and use Alt+Shift+R to refactor the resource name to TaxFilingObject:
3. When a method on the TaxFilingObject resource is called, we'll need to know the specific tax filing concerned, so we'll change the URI to taxfilings/{id}:
Note: The resource URI taxfilings/{id} is a relative URI, starting from the baseURI defined on the resourceAPI. The {id} segment of the URI is a template parameter that will be required when any methods on this resource are invoked, so we now need to add attributes to the URI definition to indicate this.
4. Place the cursor at the end of the URI line, press Enter, tab in once and press Ctrl+Space:
5. Once the template has expanded, we'll accept the default values of id and filingID by pressing Enter:
oThe URI {id} parameter is bound to the filingID property of TaxFiling (which is itself bound to the TaxFilingObject resource).  This gives the parameter special meaning with respect to the bound data type.  Generated code and documentation can capture and use this information (as we'll see later in this guide).
oThe TaxFilingObject resource supports application/xml as a media type for the communication.  The mediaTypes keyword specifies a comma-delimited list which could include media types such as application/json if required.
oThe generated resource definition includes a GET and a PUT method:
GET takes an empty request and returns a representation of this resource.  The GET method may also respond with a statusCode of 404, indicating that the specified TaxFiling was not found.
The PUT method request should contain a representation of a resource of this type. This method may respond with a statusCode of 200, indicating that the specified resource was successfully updated, or 400, indicating that the update request had bad syntax or was otherwise "inherently impossible to satisfy".
oWe could now also specify additional HTTP methods, different request and response message payloads, header parameters, request parameters and/or additional error responses on any defined method.
6. Now we need to change the GET method name from getTaxBlasterObject to getTaxFiling, and the PUT method name from putTaxBlasterObject to putTaxFiling:
Note: all we have to do is edit the method names. This is *not* a refactoring operation because the method names are not used from inside the code.

Defining the TaxFilingCollection resource

We will defer this step until later. So for now we'll simply fold and ignore the generated TaxBlasterCollection collectionResource by clicking the little minus icon in the left margin so it looks like this:

Defining the PersonObject resource

We'll now define a PersonObject resource bound to the Person data type.

1. Position the text insertion point after the TaxFilingObject:
2. Press Ctrl+Space and select the object resource template from the list:
3. When the template expands set the resource name to PersonObject:
Just start typing immediately and the resource will be updated appropriately:
4. Next, we'll use the Tab key to move to the type variable and then change the type from TaxFiling to Person:
5. Press Enter to complete the objectResource and type fields.
6. Change the URI from to people/{id}.
7. Put the cursor at the end of the URI line, press Enter, tab in once and press Ctrl+Space:
8.Select template parameter from the list and, after inserting the template, press Enter to accept the default values:
The templateParam binds the {id} URI parameter to the id property of the Person data structure from our dataModel.


Hint: Use Auto-Format

In the editor, you can use Ctrl-Shift-F to auto-format the rapidModel.  If you have text selected, auto-formatting will apply only to the selected text.  Otherwise, it applies to the entire file.

Copyright © 2016 ModelSolv, Inc.  All rights reserved. RepreZen and RAPID-ML are trademarks of ModelSolv, Inc. Swagger is a registered trademark of SmartBear Software, Inc. RepreZen API Studio is not associated with nor endorsed by SmartBear Software, Inc.