An action root to its restful methods

Introduced properties

fun async_service(str: String): HttpResponse

nitcorn :: MyAction :: async_service

Asynchronous method answering requests such as async_service?str=some_string
fun bar(s: nullable String, i: nullable Int, b: nullable Bool): HttpResponse

nitcorn :: MyAction :: bar

Method answering requests such as api_name?s=these_arguments_are_optional
fun complex_args(array: Array[String], data: MyData): HttpResponse

nitcorn :: MyAction :: complex_args

Method with two complex parameters answering requests such as
fun foo(s: String, i: Int, b: Bool): HttpResponse

nitcorn :: MyAction :: foo

Method answering requests such as foo?s=some_string&i=42&b=true

Redefined properties

redef type SELF: MyAction

nitcorn $ MyAction :: SELF

Type of this instance, automatically specialized in every class
redef fun answer(request: HttpRequest, turi: String): HttpResponse

nitcorn $ MyAction :: answer

Catch all other request

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
abstract fun answer(request: HttpRequest, truncated_uri: String): HttpResponse

nitcorn :: Action :: answer

Prepare a HttpResponse destined to the client in response to the request
fun async_service(str: String): HttpResponse

nitcorn :: MyAction :: async_service

Asynchronous method answering requests such as async_service?str=some_string
fun bar(s: nullable String, i: nullable Int, b: nullable Bool): HttpResponse

nitcorn :: MyAction :: bar

Method answering requests such as api_name?s=these_arguments_are_optional
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun complex_args(array: Array[String], data: MyData): HttpResponse

nitcorn :: MyAction :: complex_args

Method with two complex parameters answering requests such as
protected fun deserialize_arg(val: nullable String, static_type: String): nullable Object

nitcorn :: RestfulAction :: deserialize_arg

Deserialize val from JSON for a parameter typed by static_type
fun foo(s: String, i: Int, b: Bool): HttpResponse

nitcorn :: MyAction :: foo

Method answering requests such as foo?s=some_string&i=42&b=true
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
protected fun prepare_respond_and_close(request: HttpRequest, truncated_uri: String, http_server: HttpServer)

nitcorn :: Action :: prepare_respond_and_close

Full to a request with sending the response and closing of the http_server
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun thread_pool: ThreadPool

nitcorn :: RestfulAction :: thread_pool

Thread pool used by methods annotated with restful(async)
fun thread_pool=(thread_pool: ThreadPool)

nitcorn :: RestfulAction :: thread_pool=

Thread pool used by methods annotated with restful(async)
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram nitcorn::MyAction MyAction nitcorn::RestfulAction RestfulAction nitcorn::MyAction->nitcorn::RestfulAction nitcorn::Action Action nitcorn::RestfulAction->nitcorn::Action ...nitcorn::Action ... ...nitcorn::Action->nitcorn::Action

Ancestors

abstract class Action

nitcorn :: Action

Action executed to answer a request
interface Object

core :: Object

The root of the class hierarchy.

Parents

class RestfulAction

nitcorn :: RestfulAction

Action with restful methods

Class definitions

nitcorn $ MyAction
# An action root to its `restful` methods
class MyAction
	super RestfulAction

	# Method answering requests such as `foo?s=some_string&i=42&b=true`
	#
	# By default, the name of the HTTP resource is the name of the method.
	# Responds to all HTTP methods, including GET, POST, PUT and DELETE.
	#
	# All arguments are deserialized from a JSON format,
	# except for strings that are used as is.
	fun foo(s: String, i: Int, b: Bool): HttpResponse
	is restful do
		var resp = new HttpResponse(200)
		resp.body = "foo {s} {i} {b}"
		return resp
	end

	# Method answering requests such as `api_name?s=these_arguments_are_optional`
	#
	# This method is available as both `api_name` and `alt_name` in HTTP.
	# Responds only to the GET and PUT HTTP method.
	fun bar(s: nullable String, i: nullable Int, b: nullable Bool): HttpResponse
	is restful("api_name", "alt_name", GET, PUT) do

		var resp = new HttpResponse(200)
		resp.body = "bar {s or else "null"} {i or else "null"} {b or else "null"}"
		return resp
	end

	# Asynchronous method answering requests such as `async_service?str=some_string`
	#
	# This method is executed by the `thread_pool` attribute of this class.
	# Be careful when using the `async` argument to follow all the good
	# concurrent programming pratices.
	fun async_service(str: String): HttpResponse
	is restful(async) do

		# "Work" for 2 seconds
		2.0.sleep

		# Answer
		var resp = new HttpResponse(200)
		resp.body = "async_service {str}"
		return resp
	end

	# Method with two complex parameters answering requests such as
	# `complex_args?array=["a","b"]&data={"str":"asdf","more":{"str":"ASDF"}}`
	#
	# Collections and other classes can also be used as parameters,
	# they will be deserialized from JSON format.
	# By default, the JSON objects will be parsed as the type of the parameter.
	# In the example above, the argument passed as `data` is deserialized as a `MyData`.
	# However, you can use metadata in the JSON object to deserialize it
	# as a subclass of `MyData`, as in this request where `data` is a `MyOtherData`:
	#
	# `complex_args?array=["a","b"]&data={"__class":"MyOtherData","str":"asdf","i":1234}`
	#
	# See the `json` package documentation for more information on JSON
	# deserialization and the metadata values.
	fun complex_args(array: Array[String], data: MyData): HttpResponse
	is restful do
		var resp = new HttpResponse(200)
		resp.body = "complex_args {array} {data}"
		return resp
	end

	# Catch all other request
	redef fun answer(request, turi)
	do
		var resp = new HttpResponse(404)
		resp.body = "Fallback answer"
		return resp
	end
end
lib/nitcorn/examples/src/restful_annot.nit:21,1--96,3