jkuester:public-api

v0.0.4Published 7 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Meteor Public API

Helps you to expose, what is public, while you code. Just import the PublicApi class and add definitions directly when you define them.

Usage

1
2import { PublicAPI } from "meteor/jkuester:public-api";
3
4PublicAPI.setName("MY-MICROSERVICE-NAME");
5PublicAPI.setDescription("describe what your application/microservice does...")

In your app you declare a method the usual way

1const MY_PUBLIC_METHOD = "my_public_method";
2Meteor.methods(MY_PUBLIC_METHOD, function(){ /* some code */ });

And then expose it to the api:

1PublicAPI.addMethod(MY_PUBLIC_METHOD, "description of what your method does....");

Same with collections

1const MY_COLLECTION_NAME = "myCollectionName";
2export MyCollection = new Mongo.Collection(MY_COLLECTION_NAME);
3PublicAPI.addCollection(MY_COLLECTION_NAME, "a simple collection without schema");

And the same with publlications...

1const PUBCIC_DATA_FROM_MY_COLLECTION = "publicDataFromMyCollectio";
2Meteor.publish(PUBCIC_DATA_FROM_MY_COLLECTION, function(){ /* some code */ });
3PublicAPI.addPublication(PUBCIC_DATA_FROM_MY_COLLECTION, "tells my collection: show me what you got");

At the end of all your definitions, you call

1PublicAPI.publish("api.json", "path/to/public/", "subpath/in/public"/*, optionalCallback */);

And in your public folder will be something like this:

1{
2    "name": "public-api-test-package",
3    "desription": "some public description",
4    "urls": {
5        "default": "http://localhost:3000",
6        "fallback": "http://localhost:3333"
7    },
8    "methods": {
9        "get_all_methods": "a method which returns a list of all methods",
10        "some_call": "some other methods"
11    },
12    "publications": {
13        "get_all_docs": "gets all documents",
14        "get_other_docs": "gets som other documents"
15    },
16    "collections": {
17        "logs": "a log collection",
18        "dogs": "a dog collection"
19    }
20}

LICENCE

MIT, see licence file.