c

org.coursera.naptime.actions

RestActionBuilder

class RestActionBuilder[RACType, AuthType, BodyType, ResourceKeyType, ResourceType, ResponseType] extends RestActionBuilderTerminators[RACType, AuthType, BodyType, ResourceKeyType, ResourceType, ResponseType]

A builder that helps build Rest Actions.

Linear Supertypes
RestActionBuilderTerminators[RACType, AuthType, BodyType, ResourceKeyType, ResourceType, ResponseType], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. RestActionBuilder
  2. RestActionBuilderTerminators
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new RestActionBuilder(auth: HeaderAccessControl[AuthType], bodyParser: BodyParser[BodyType], errorHandler: PartialFunction[Throwable, RestError])(implicit keyFormat: KeyFormat[ResourceKeyType], resourceFormat: OFormat[ResourceType], application: Application)

Type Members

  1. type ActionBuilder[A] = RestActionBodyBuilder[ActionRestActionCategory, AuthType, BodyType, ResourceKeyType, ResourceType, A]

    Arbitrary actions on objects that are not standard CRUD operations.

    Arbitrary actions on objects that are not standard CRUD operations. This is very flexible, and must be carefully used only for good (and not evil). Actions may have side effects and may not be idempotent.

    Example:

    def convertToHtml(ids: Seq[Int]) = Rest.action { ctx =>
      val pages = store.multiGet(ids)
      val htmlIfied = pages.map { page =>
        MarkdownEngine.toHtml(page)
      }
      store.multiSave(htmlIfied)
      Ok(htmlIfied)
    }

    Underlying HTTP request (ids=1,2,3,5,8,13):

    POST /api/myResource?action=convertToHtml&ids=1,2,3,5,8,13
    Definition Classes
    RestActionBuilderTerminators
  2. type BodyBuilder[Category, Response] = RestActionBodyBuilder[Category, AuthType, BodyType, ResourceKeyType, ResourceType, Response]
    Definition Classes
    RestActionBuilderTerminators
  3. type CreateBuilder = RestActionBodyBuilder[CreateRestActionCategory, AuthType, BodyType, ResourceKeyType, ResourceType, Keyed[ResourceKeyType, Option[ResourceType]]]

    Creates a new resource given an input.

    Creates a new resource given an input.

    Example:

    def create = Rest.create { ctx =>
      val newElement = createResourceFromBody(ctx.body)
      val newId = store.save(newOne)
      Ok(Keyed(newId, Some(newElement)))
    }

    Underlying HTTP request (body elided):

    POST /api/myResource
    Definition Classes
    RestActionBuilderTerminators
  4. type DeleteBuilder = RestActionBodyBuilder[DeleteRestActionCategory, AuthType, BodyType, ResourceKeyType, ResourceType, Unit]

    Deletes an element from a collection.

    Deletes an element from a collection.

    Example:

    def delete(id: Int) = Rest.delete { ctx =>
      store.delete(id)
      Ok()
    }

    Underlying HTTP request (id=4):

    DELETE /api/myResource/4
    Definition Classes
    RestActionBuilderTerminators
  5. type FinderBuilder = RestActionBodyBuilder[FinderRestActionCategory, AuthType, BodyType, ResourceKeyType, ResourceType, FinderResponseType]
    Definition Classes
    RestActionBuilderTerminators
  6. type FinderResponseType = Seq[Keyed[ResourceKeyType, ResourceType]]

    Retrieval by any method other than retrival by Id [primary key].

    Retrieval by any method other than retrival by Id [primary key]. (For example, alternate key lookup, or full text search. This is intentionally a flexible API and can be used appropriately in many contexts. A finder MUST NOT have side effects, and must be idempotent.

    Example:

    def alternateKey(name: String) = Rest.finder { ctx =>
      val results = store.lookupByName(name=name)
      Ok(results.toSeq)
    }

    Underlying HTTP request (finder name='alternateKey', name='hogwarts'):

    GET /api/myResource?q=alternateKey&name=hogwarts
    Definition Classes
    RestActionBuilderTerminators
  7. type GetAllBuilder = RestActionBodyBuilder[GetAllRestActionCategory, AuthType, BodyType, ResourceKeyType, ResourceType, Seq[Keyed[ResourceKeyType, ResourceType]]]

    Gets all elements in a collection.

    Gets all elements in a collection. Note: please use paging to avoid OOM-ing.

    Example:

    def getAll = Rest.getAll { ctx =>
      val results = store.getAll(start=ctx.paging.start, limit=ctx.paging.limit)
      Ok(results)
    }

    Underlying HTTP request (pagination: start=10, limit=5)

    GET /api/myResource?start=10&limit=5
    Definition Classes
    RestActionBuilderTerminators
  8. type GetBuilder = RestActionBodyBuilder[GetRestActionCategory, AuthType, BodyType, ResourceKeyType, ResourceType, Keyed[ResourceKeyType, ResourceType]]

    Gets a resource by ID

    Gets a resource by ID

    Example:

    def get(id: Int) = Rest.get { ctx =>
      Ok(Keyed(id, MyResource(name=s"Resource-$id")))
    }

    Underlying HTTP request (id = "1"):

    GET /api/myResource/1
    Definition Classes
    RestActionBuilderTerminators
  9. type MultiGetBuilder = RestActionBodyBuilder[MultiGetRestActionCategory, AuthType, BodyType, ResourceKeyType, ResourceType, Seq[Keyed[ResourceKeyType, ResourceType]]]

    Gets a batch of resources from this collection.

    Gets a batch of resources from this collection.

    Example:

    def multiGet(ids: Seq[Int]) = Rest.multiGet { ctx =>
      Ok(ids.map(id => Keyed(id, MyResource(name=s"Resource-$id"))))
    }

    Underlying HTTP request (ids = "1,2,3,4")

    GET /api/myResource?ids=1,2,3,4
    Definition Classes
    RestActionBuilderTerminators
  10. type PatchBuilder = RestActionBodyBuilder[PatchRestActionCategory, AuthType, BodyType, ResourceKeyType, ResourceType, Keyed[ResourceKeyType, ResourceType]]

    Patch (or partial update) a resource.

    Patch (or partial update) a resource.

    Example:

    def patch(id: Int) = Rest.patch { ctx =>
      val oldObj = store.get(id)
      val newObj = PatchEngine.patch(oldObj, ctx.body)
      store.save(id, newObj)
      Ok(Keyed(id, newObj))
    }

    Underlying HTTP request (id=10, body elided):

    PATCH /api/myResource/10
    Definition Classes
    RestActionBuilderTerminators
  11. type UpdateBuilder = RestActionBodyBuilder[UpdateRestActionCategory, AuthType, BodyType, ResourceKeyType, ResourceType, Option[Keyed[ResourceKeyType, ResourceType]]]

    Updates a resource with a new copy of the resource.

    Updates a resource with a new copy of the resource.

    Example:

    def update(id: Int) = Rest.update { ctx =>
      val newVersion = validateBody(ctx.body)
      store.save(id, newVersion)
      Ok(Keyed(id, newVersion))
    }

    Underlying HTTP request (body elided, id=2):

    PUT /api/myResource/2
    Definition Classes
    RestActionBuilderTerminators

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def action[A]: ActionBuilder[A]
    Definition Classes
    RestActionBuilderTerminators
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def auth[NewAuthType](auth: HeaderAccessControl[NewAuthType]): RestActionBuilder[RACType, NewAuthType, BodyType, ResourceKeyType, ResourceType, ResponseType]

    Set the authentication framework.

  7. def body[NewBodyType](bodyParser: BodyParser[NewBodyType]): DefinedBodyTypeRestActionBuilder[RACType, AuthType, NewBodyType, ResourceKeyType, ResourceType, ResponseType]

    Set the body type.

  8. def bodyBuilder[Category, Response](): BodyBuilder[Category, Response]
    Attributes
    protected
    Definition Classes
    RestActionBuilder → RestActionBuilderTerminators
  9. def catching(errorHandler: PartialFunction[Throwable, RestError]): RestActionBuilder[RACType, AuthType, BodyType, ResourceKeyType, ResourceType, ResponseType]

    Adds an error handling function to allow exceptions to generate custom errors.

    Adds an error handling function to allow exceptions to generate custom errors.

    Note: all of the partial functions are stacked, with later functions getting an earlier crack at an exception to handle it.

    errorHandler

    Error handling partial function.

    returns

    the immutable RestActionBuilder to be used to build the naptime resource action.

  10. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  11. def create: CreateBuilder
    Definition Classes
    RestActionBuilderTerminators
  12. def delete: DeleteBuilder
    Definition Classes
    RestActionBuilderTerminators
  13. implicit val ec: ExecutionContext
  14. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  16. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. def finder: FinderBuilder
    Definition Classes
    RestActionBuilderTerminators
  18. def get: GetBuilder
    Definition Classes
    RestActionBuilderTerminators
  19. def getAll: GetAllBuilder
    Definition Classes
    RestActionBuilderTerminators
  20. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  21. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  22. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  23. def jsonBody[NewBodyType](maxLength: Int = 100 * 1024)(implicit reads: Reads[NewBodyType]): DefinedBodyTypeRestActionBuilder[RACType, AuthType, NewBodyType, ResourceKeyType, ResourceType, ResponseType]
  24. def jsonBody[NewBodyType](implicit reads: Reads[NewBodyType]): DefinedBodyTypeRestActionBuilder[RACType, AuthType, NewBodyType, ResourceKeyType, ResourceType, ResponseType]
  25. def multiGet: MultiGetBuilder
    Definition Classes
    RestActionBuilderTerminators
  26. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  27. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  28. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  29. def patch: PatchBuilder
    Definition Classes
    RestActionBuilderTerminators
  30. def rawJsonBody(maxLength: Int = 100 * 1024): DefinedBodyTypeRestActionBuilder[RACType, AuthType, JsValue, ResourceKeyType, ResourceType, ResponseType]
  31. def returning[NewResponseType](): RestActionBuilder[RACType, AuthType, BodyType, ResourceKeyType, ResourceType, NewResponseType]

    Set the response type.

    Set the response type. TODO: is this necessary?

  32. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  33. def toString(): String
    Definition Classes
    AnyRef → Any
  34. def update: UpdateBuilder
    Definition Classes
    RestActionBuilderTerminators
  35. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  36. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  37. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from RestActionBuilderTerminators[RACType, AuthType, BodyType, ResourceKeyType, ResourceType, ResponseType]

Inherited from AnyRef

Inherited from Any

Ungrouped