A MVC based, yet arguably liberal RESTful API framework. Includes routing, controllers, models, utilities, and a MongoDB interface.
- Install
- Documentation
- Change Log
- Creating a new application
- Starting a Server
- Starting a Console
- Application Structure
- Issues
- Community
- License
pineapple
requires global installation for the CLI utilitiy. If you do not plan on using pineapple to manage a pineapple
application from the command line then using it as a local module is fine.
$ [sudo] npm install -g pineapple
pineapple gen <name>
Creating a pineapple application can easily be achieved with pineapple gen
$ pineapple gen myapp
[pineapple] => Going to grab all of those dependencies now..
[pineapple] => This may take a while..
[pineapple] => Sweet! I've created a new Pineapple application here => /Users/werle/myapp
pineapple server
Starting a pineapple server of a pineapple application is as simple as executing pineapple server
from the directory of
the pineapple application.
$ pineapple server
Requiring app module /config/environment
Requiring app module /config/development
Requiring app module /config/application
Requiring app module /config/routes.js
Requiring app module /app/controllers
Requiring app module /app/models
[app] => Found the Paplfile file. => /Users/werle/repos/myapp/Paplfile
[server] => Listening on port 4000
You could utilize the pineapple module and create your own server without using a skeleton pineapple application.
The contents of the app.js
file below whose only dependency is pineapple
demonstrates the process
of using pineapple in node with minimal requirements. Consider the following app structure:
├── app.js
└── node_modules
└── pineapple (pineapple module)
You could then use pineapple to create a server, bind routes, and listen on a port to start the service.
// it isn't needed to store pineapple in a variable as it is attached
// to the global object during its bootstrap
require('pineapple');
// define an app name
var appName = "myService";
// server config
var serverConfig = {
config : {
name : appName
}
};
// Let pineapple no about your app name
pineapple.app.name = appName;
// we can create a server with minimal configuration
pineapple.api.create(serverConfig);
/**
* In order for your server to work we will need some routes set up.
* That can easily be achieved with pineapple's built in router.
*
* The Router supports basic POST, GET, PUT, and DELETE protocols via
* convenience methods:
* router.post(uri_path, [controller_path|callback]); // POST
* router.get(uri_path, [controller_path|callback]); // GET
* router.put(uri_path, [controller_path|callback]); // PUT
* router.del(uri_path, [controller_path|callback]); // DELETE
*
* If you need to set a custom method you can call .create() directly:
* router.create(CUSTOM_METHOD, uri_path, [controller_path|callback]);
**/
// we need to create a router instance
var router = new pineapple.router.Router();
// lets get a "Hello world" going
router.get('/hello', function(request, response){
var request = this.request
, response = this.response
// output some sanity
pineapple.api.logger.success("Got the request, emitting response..");
// response with a json response
this.json({
message : "Hello world! I'm a pineapple api server."
});
});
// we need to bind the routes we just created to the server
pineapple.api.bindRoutes(router.routes);
// once all is said and done, we can finally start the server
// the .listen() method accept a port and a callback for arguments
pineapple.api.listen(4000);
From the command line you can then execute the app.js
file with the node
executable
which will output something like this:
$ node app.js
From the browser or from a program like cURL you could hit the following url http://localhost:4000/hello
while your app is running.
$ curl http://localhost:4000/hello
{"code":200,"status":true,"data":{"message":"Hello world! I'm a pineapple api server."}}
$ pineapple console
...
everybit-local> pineapple.models
{ User: { [Function: User] super: [Function] },
Profile: { [Function: Profile] super: [Function] },
CreditCard: { [Function: CreditCard] super: [Function] },
Video: { [Function: Video] super: [Function] },
Version: { [Function: Version] super: [Function] },
Media: { [Function: Media] super: [Function] },
Image: { [Function: Image] super: [Function] },
Blurb: { [Function: Blurb] super: [Function] },
Audio: { [Function: Audio] super: [Function] },
user:
{ User: { [Function: User] super: [Function] },
Profile: { [Function: Profile] super: [Function] },
CreditCard: { [Function: CreditCard] super: [Function] } },
media:
{ Video: { [Function: Video] super: [Function] },
Version: { [Function: Version] super: [Function] },
Media: { [Function: Media] super: [Function] },
Image: { [Function: Image] super: [Function] },
Blurb: { [Function: Blurb] super: [Function] },
Audio: { [Function: Audio] super: [Function] } },
getSchema: [Function] }
everybit-local>
myapp/
├── Capfile
├── Jakefile
├── Paplfile
├── Procfile
├── README.md
├── app
│ ├── controllers
│ │ ├── Application.js
│ │ ├── index.js
│ │ └── pineapple
│ │ ├── Api.js
│ │ └── index.js
│ └── models
│ └── index.js
├── config
│ ├── README.md
│ ├── application.json
│ ├── development.json
│ ├── environment.json
│ ├── production.json
│ └── routes.js
├── index.js
├── package.json
└── test
└── app
└── README.md
Submit all bugs here
Join the google group here
IRC? Hang out with us at #papl
Copyright 2012
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
pineapple copyright 2012 werle.io - [email protected]