Package: grails.rest

## [Groovy] Class RestfulController<T>

- grails.rest.RestfulController

- Base class that can be extended to get the basic CRUD operations needed for a RESTful API.

  Authors:
    Graeme Rocher
  Since:
    2.3

- - ### Properties Summary

    Properties
    Type | Name and description
    --- | ---
    `static java.lang.Object` | `allowedMethods`
    `boolean` | `readOnly`
    `java.lang.Class<T>` | `resource`
    `java.lang.String` | `resourceClassName`
    `java.lang.String` | `resourceName`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `RestfulController (java.lang.Class<T> resource)`
    `RestfulController (java.lang.Class<T> resource, boolean readOnly)`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected java.lang.Integer` | `countResources()` Counts all of resources
    `` | `java.lang.Object` | `create()` Displays a form to create a new resource
    `` | `protected T` | `createResource(java.util.Map params)` Creates a new instance of the resource for the given parameters
    `` | `protected T` | `createResource()` Creates a new instance of the resource.
    `` | `java.lang.Object` | `delete()` Deletes a resource for the given id
    `` | `protected void` | `deleteResource(T resource)` Deletes a resource
    `` | `java.lang.Object` | `edit()`
    `` | `protected java.lang.String` | `getClassMessageArg()`
    `` | `protected java.lang.Object` | `getObjectToBind()` The object that can be bound to a domain instance.
    `` | `protected boolean` | `handleReadOnly()` handles the request for write methods (create, edit, update, save, delete) when controller is in read only mode
    `` | `java.lang.Object` | `index(java.lang.Integer max)` Lists all resources up to the given maximum
    `` | `protected java.util.List<T>` | `listAllResources(java.util.Map params)` List all of resource based on parameters
    `` | `protected void` | `notFound()`
    `` | `java.lang.Object` | `patch()` Updates a resource for the given id
    `` | `protected T` | `queryForResource(java.io.Serializable id)` Queries for a resource for the given id
    `` | `java.lang.Object` | `save()` Saves a resource
    `` | `protected T` | `saveResource(T resource)` Saves a resource
    `` | `java.lang.Object` | `show()` Shows a single resource
    `` | `java.lang.Object` | `update()` Updates a resource for the given id
    `` | `protected T` | `updateResource(T resource)` Updates a resource

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Property Detail

    - #### static java.lang.Object allowedMethods

    - #### boolean readOnly

    - #### java.lang.Class<T> resource

    - #### java.lang.String resourceClassName

    - #### java.lang.String resourceName

  - ### Constructor Detail

    - #### RestfulController(java.lang.Class<T> resource)

    - #### RestfulController(java.lang.Class<T> resource, boolean readOnly)

  - ### Method Detail

    - #### protected java.lang.Integer countResources()

      Counts all of resources

      Returns:
        List of resources or empty if it doesn't exist

    - #### java.lang.Object create()

      Displays a form to create a new resource

    - #### protected T createResource(java.util.Map params)

      Creates a new instance of the resource for the given parameters

      Parameters:
        `params` - The parameters
      Returns:
        The resource instance

    - #### protected T createResource()

      Creates a new instance of the resource. If the request contains a body the body will be parsed and used to initialize the new instance, otherwise request parameters will be used to initialized the new instance.

      Returns:
        The resource instance

    - #### @Transactional java.lang.Object delete()

      Deletes a resource for the given id

      Parameters:
        `id` - The id

    - #### protected void deleteResource(T resource)

      Deletes a resource

      Parameters:
        `resource` - The resource to be deleted

    - #### java.lang.Object edit()

    - #### protected java.lang.String getClassMessageArg()

    - #### protected java.lang.Object getObjectToBind()

      The object that can be bound to a domain instance. Defaults to the request. Subclasses may override this method to return anything that is a valid second argument to the bindData method in a controller. This could be the request, a java.util.Map or a org.grails.databinding.DataBindingSource.

      Returns:
        the object to bind to a domain instance

    - #### protected boolean handleReadOnly()

      handles the request for write methods (create, edit, update, save, delete) when controller is in read only mode

      Returns:
        true if controller is read only

    - #### java.lang.Object index(java.lang.Integer max)

      Lists all resources up to the given maximum

      Parameters:
        `max` - The maximum
      Returns:
        A list of resources

    - #### protected java.util.List<T> listAllResources(java.util.Map params)

      List all of resource based on parameters

      Returns:
        List of resources or empty if it doesn't exist

    - #### protected void notFound()

    - #### @Transactional java.lang.Object patch()

      Updates a resource for the given id

      Parameters:
        id

    - #### protected T queryForResource(java.io.Serializable id)

      Queries for a resource for the given id

      Parameters:
        `id` - The id
      Returns:
        The resource or null if it doesn't exist

    - #### @Transactional java.lang.Object save()

      Saves a resource

    - #### protected T saveResource(T resource)

      Saves a resource

      Parameters:
        `resource` - The resource to be saved
      Returns:
        The saved resource or null if can't save it

    - #### java.lang.Object show()

      Shows a single resource

      Parameters:
        `id` - The id of the resource
      Returns:
        The rendered resource or a 404 if it doesn't exist

    - #### @Transactional java.lang.Object update()

      Updates a resource for the given id

      Parameters:
        id

    - #### protected T updateResource(T resource)

      Updates a resource

      Parameters:
        `resource` - The resource to be updated
      Returns:
        The updated resource or null if can't save it