MVC of the Application
The Beapi API Framework has several built-in tools to help you get started that will automate most of the development/build for you. Below is an explaination of those tools and how to use them.
The Domains
NOTE: See Grails documentation on Domains.
Your Model requires no additional annotations added to it to make the api's function. You merely need to map the database tables like a normal model. Included in the project are several domain classes to show you how one should look. There is nothing complex; just follow GORM principles for creating a basic domain object.
The Controllers
NOTE: See Grails documentation on Controllers.
NOTE:If you would like to simplify this process, see 'Bootstrapping : Generate API Controllers'
Your controllers requires no additional annotations (or ROLE checks) added to it to make the api's function. Included in the project are several controllers to show you how one should look.
There ARE two caveats to your controller methods however:
- Every API method in the controller has to be declared as returning 'LinkedHashMap'. For example:
LinkedHashMap show(){ ... }
- The return value KEY has to be the class name in camelCase. For example, in the above link provided where the controller class in 'PersonController', we would need the key to be 'person':
return [person: someValue]
Building The Project
While Grails documentation may tell you how to build your project, thebest (and easiest way) to build and test your project is as follows; go into the ROOT of your project and run the following command:
./gradlew clean;./gradlew build
Troubleshooting
- If you are having problems with a domain class, remove 'cache: true'; this usually takes care of the problem.
- If you are bootstrapping your controllers, make sure all your corresponding domains exist first.
- If you asre having issues with your build, try running './gradlew --stop;./gradlew clean;./gradlew build --stacktrace --refresh-dependencies'. This will give you a fresh gradle instance, show your errors and refresh all dependencies.