carbond.Collection¶
Carbond Collection
s provide a high-level abstraction for defining Endpoint
s that behave like a collection of
resources. When you define a Collection
you define the following methods:
insert(obj, reqCtx)
find(query, options, reqCtx)
update(query, obj, options, reqCtx)
remove(query, reqCtx)
findObject(id, reqCtx)
updateObject(id, reqCtx)
removeObject(id, reqCtx)
Which results in the following tree of Endpoints
and Operations
:
/<collection>
GET
which maps tofind
POST
which maps toinsert
PUT
which maps toupdate
DELETE
which maps toremove
/<collection>/:id
GET
which maps tofindObject
PUT
which maps toupdateObject
DELETE
which maps toremoveObject
Configuration¶
{
_type: carbon.carbond.Collection, // extends Endpoint
[parameters: {
<name> : <OperationParameter>
}]
[insert: <function>],
[find: <function>],
[update: <function>],
[remove: <function>],
[findObject: <function>],
[updateObject: <function>],
[removeObject: <function>]
[endpoints: {
<path>: <Endpoint>
...
}]
}
Properties¶
- ¶
(read-only): The path to which this
Collection
is bound. The path can contain variable patterns (e.g.'orgs/:id/members'
). Thepath
property is not configured directly onCollection
objects but are specified as lvals in enclosing definitions of endpoints such as in anObjectServer
or a parentEndpoint
object. When retrieved the value of this property will be the absolute path of the endpoint from/
.
- ¶
(read-only): The parent
Endpoint
of thisCollection
.
- ¶
(read-only): The
ObjectServer
to which this endpoint belongs.
Methods¶
- ¶
find Arguments - arg1 (Collection) – The first argument
Returns Something Description Foo!
RESTFul interface¶
/<collection>
GET
which maps tofind
POST
which maps toinsert
PUT
which maps toupdate
DELETE
which maps toremove
/<collection>/:id
GET
which maps tofindObject
PUT
which maps toupdateObject
DELETE
which maps toremoveObject
Examples (synchronous)¶
__(function() {
module.exports = o({
_type: carbon.carbond.ObjectServer,
port: 8888,
dbUri: "mongodb://localhost:27017/mydb",
endpoints: {
feedback: o({
_type: carbon.carbond.Collection,
insert: function(obj) {
return this.objectserver.db.getCollection('feedback').insert(obj)
}
})
}
})
})