Once you have finished the designing of your REST Resource(s), you can generate the API and optionally, the API documentation.
Generating REST API
To generate REST API:
- Select Tools > Code > Generate REST API… from the toolbar.
- In the REST API window, keep Provider selected for API Type. By doing so, you will be able to generate API documentation as well as the server sample code that guides you in programming your service (logic).
- Select the REST Resource to generate to code.
- The generator will use the templates stored in the Template directory for code generation. You may edit the templates or select another directory as template directory.
- Check Generate API Documentation to generate the HTML files that shows how to use the selected REST Resource(s). Supposedly, you will publish the generated API documentation in your website so that the consumers of your service can read through it to know how to access for your service.
- Enter your company name, which will be presented in the API documentation.
- Enter the base URL of your services.
- Check Generate Sample to generate the source code that teaches you how to program your service. The sample code is rich and informative. Therefore, instead of programming from scratch, we strongly recommend you to generate the sample code and modify its content to fit your needs.
- Enter the output path of the code.
- Click Generate. Depending on the option checked/unchecked, you may see the following folders in the output directory.
Folder Description doc The API documentation. You should publish the API documentation in your website, so that the consumers of your service can check the documentation to learn the API. lib In order for the generated code to work, the Google Gson library must be presented in your class path. To avoid any compatibility issues, please download library manually:
https://code.google.com/p/google-gson/and then place the file in the lib folder.sample_src The sample code of client and servlet. It shows you how to access as client and how to react to a request as provider. We strongly recommend you to copy the code and modify it by filling in your own service logic. src The source code of the communication model. Do not modify the file content or else the code may not be able to function properly.