api.md 4.1 KB

http-publish Public API

Adds HTTP.publish and HTTP.unpublish RESTful

API documentation automatically generated by docmeteor.

-

_publishHTTP {any}  Server

GET /note
GET /note/:id
POST /note
PUT /note/:id
DELETE /note/:id



-
Could be cool if we could serve some api doc or even an api script
user could do <script href="/note/api?token=1&user=2"></script> and be served
a client-side javascript api?
Eg.
HTTP.api.note.create();
HTTP.api.login(username, password);
HTTP.api.logout
-

### <a name="HTTP.publishFormats"></a>*http*.publishFormats(newHandlers)&nbsp;&nbsp;<sub><i>Server</i></sub> ###

*This method __publishFormats__ is defined in `HTTP`*

__Arguments__

* __newHandlers__ *{Object}*  

__Returns__  *{undefined}*


Add publish formats. Example:

js HTTP.publishFormats({ json: function(inputObject) { // Set the method scope content type to json this.setContentType('application/json'); // Return EJSON string return EJSON.stringify(inputObject); } });


HTTP.publishFormats = function httpPublishFormats(newHandlers) { ...``` http.publish.server.api.js:215

-

http.publish(options, [name], [collection], [publishFunc])  Server

This method publish is defined in HTTP

Arguments

  • options {Object}

    • defaultFormat {String} (Optional, Default = 'json')

    Format to use for responses when format is not found in the query string.

    • collectionGet {String} (Optional, Default = true)

    Add GET restpoint for collection? Requires a publish function.

    • collectionPost {String} (Optional, Default = true)

    Add POST restpoint for adding documents to the collection?

    • documentGet {String} (Optional, Default = true)

    Add GET restpoint for documents in collection? Requires a publish function.

    • documentPut {String} (Optional, Default = true)

    Add PUT restpoint for updating a document in the collection?

    • documentDelete {String} (Optional, Default = true)

    Add DELETE restpoint for deleting a document in the collection?

  • name {String} (Optional)

Restpoint name (url prefix). Optional if collection is passed. Will mount on /api/collectionName by default.

Meteor.Collection instance. Required for all restpoints except collectionGet

  • publishFunc {Function} (Optional)

A publish function. Required to mount GET restpoints.

Returns {undefined}

Publishes one or more restpoints, mounted on "name" ("/api/collectionName/" by default). The GET restpoints are subscribed to the document set (cursor) returned by the publish function you supply. The other restpoints forward requests to Meteor's built-in DDP methods (insert, update, remove), meaning that full allow/deny security is automatic.

Usage:

Publish only:

HTTP.publish({name: 'mypublish'}, publishFunc);

Publish and mount crud rest point for collection /api/myCollection:

HTTP.publish({collection: myCollection}, publishFunc);

Mount CUD rest point for collection and documents without GET:

HTTP.publish({collection: myCollection});

HTTP.publish = function httpPublish(options, publishFunc) { ... http.publish.server.api.js:256

-

http.unpublish([name])  Server

This method unpublish is defined in HTTP

Arguments

The method name or collection

Returns {undefined}

Unpublishes all HTTP methods that were published with the given name or for the given collection. Call with no arguments to unpublish all.

HTTP.unpublish = _publishHTTP.unpublish; http.publish.server.api.js:453