Your SlideShare is downloading. ×
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

How to quickly make REST APIs with CompoundJS

1,601

Published on

Presentation of the backend features provided by CompoundJS a full-featured web framework for Node.js …

Presentation of the backend features provided by CompoundJS a full-featured web framework for Node.js

http://compoundjs.com/
https://github.com/1602/compound/

Talk performed @ LyonJS Meetup, April 2013

Published in: Business, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,601
On Slideshare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
8
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. How to quickly make REST APIs
  • 2. infosmade by Anatoliy Chakkaev1208 stars on github1000+ commitspreviously named RailwayJS
  • 3. based on top of ExpressJSExpress is inspired by Sinatra: simple and light  Express has cool stuff: middlewares, error  handling, logging...
  • 4. an express serverexpress = require expressapp = express()app.get /hello, (req, res) -> res.end hello: world
  • 5. Neat but almost nothing is configured by default.
  • 6. compoundinspired by Rails: full featured and scaffolding  quickstartcompound init blog-api --coffee
  • 7. configurationLoad dependenciescd blog-apinpm installBackend only: we remove UIrm -rf public app/assets app/views# remove code from config/environment.coffee- app.use compound.assetsCompiler.init()- app.set cssEngine, stylus- app.use express.static #{app.root}/public, maxAge: 86400000
  • 8. our filesapp/app/models/app/controllers/app/controllers/application_controller.coffeeapp/observers/app/helpers/db/db/schema.coffeelog/node_modules/config/config/locales/config/initializers/config/environments/config/environment.coffeeconfig/environments/development.coffeeconfig/environments/production.coffeeconfig/environments/test.coffeeconfig/initializers/db-tools.coffeeconfig/routes.coffeeconfig/autoload.coffeeconfig/database.coffeeserver.coffeeREADME.mdpackage.json
  • 9. routesapp/app/models/app/controllers/app/controllers/application_controller.coffeeapp/observers/app/helpers/db/db/schema.coffeelog/node_modules/config/config/locales/config/initializers/config/environments/config/environment.coffeeconfig/environments/development.coffeeconfig/environments/production.coffeeconfig/environments/test.coffeeconfig/initializers/db-tools.coffeeconfig/routes.coffeeconfig/autoload.coffeeconfig/database.coffeeserver.coffeeREADME.mdpackage.json
  • 10. controllersapp/app/models/app/controllers/app/controllers/application_controller.coffeeapp/observers/app/helpers/db/db/schema.coffeelog/node_modules/config/config/locales/config/initializers/config/environments/config/environment.coffeeconfig/environments/development.coffeeconfig/environments/production.coffeeconfig/environments/test.coffeeconfig/initializers/db-tools.coffeeconfig/routes.coffeeconfig/autoload.coffeeconfig/database.coffeeserver.coffeeREADME.mdpackage.json
  • 11. modelsapp/app/models/app/controllers/app/controllers/application_controller.coffeeapp/observers/app/helpers/db/db/schema.coffeelog/node_modules/config/config/locales/config/initializers/config/environments/config/environment.coffeeconfig/environments/development.coffeeconfig/environments/production.coffeeconfig/environments/test.coffeeconfig/initializers/db-tools.coffeeconfig/routes.coffeeconfig/autoload.coffeeconfig/database.coffeeserver.coffeeREADME.mdpackage.json
  • 12. log, dependencies, infosapp/app/models/app/controllers/app/controllers/application_controller.coffeeapp/observers/app/helpers/db/db/schema.coffeelog/node_modules/config/config/locales/config/initializers/config/environments/config/environment.coffeeconfig/environments/development.coffeeconfig/environments/production.coffeeconfig/environments/test.coffeeconfig/initializers/db-tools.coffeeconfig/routes.coffeeconfig/autoload.coffeeconfig/database.coffeeserver.coffeeREADME.mdpackage.json
  • 13. configapp/app/models/app/controllers/app/controllers/application_controller.coffeeapp/observers/app/helpers/db/db/schema.coffeelog/node_modules/config/config/locales/config/initializers/config/environments/config/environment.coffeeconfig/environments/development.coffeeconfig/environments/production.coffeeconfig/environments/test.coffeeconfig/initializers/db-tools.coffeeconfig/routes.coffeeconfig/autoload.coffeeconfig/database.coffeeserver.coffeeREADME.mdpackage.json
  • 14. start + commandsapp/app/models/app/controllers/app/controllers/application_controller.coffeeapp/observers/app/helpers/db/db/schema.coffeelog/node_modules/config/config/locales/config/initializers/config/environments/config/environment.coffeeconfig/environments/development.coffeeconfig/environments/production.coffeeconfig/environments/test.coffeeconfig/initializers/db-tools.coffeeconfig/routes.coffeeconfig/autoload.coffeeconfig/database.coffeeserver.coffeeREADME.mdpackage.json
  • 15. models and JugglingDBORM/ODM for Node.jsIntegrated with Compoundadaptable to any data sourcevalidatorsrelations
  • 16. generatorcompound g model post title content published:booleanrenders:# db/schema.coffeePost = describe Post, -> property title, String property content, String property published, Boolean# app/models/post.coffeemodule.exports = (compound, Post) →lets add this: Post.published = (callback) -> Post.all published: true, callback
  • 17. controllers# app/controllers/posts_controller.coffeeaction create, -> Post.create body (err, post) -> if err then send 500 else send post, 201action all, -> Post.all (err, posts) -> if err then send 500 else send postsaction published, -> Post.published (err, posts) -> if err then send 500 else send posts
  • 18. pre-processors and post-processorsbefore -> Post.find params.id, (err, post) => if err then send 500 else if not post then send 404 else @post = post next(), only: [show, update, destroy]after -> console.log request processed next()
  • 19. That makes simpler controllers!  action show, -> send @postaction update, -> @post.updateAttributes body, (err) -> if err then send 500 else send 200action destroy, -> @post.destroy -> if err then send 500 else send 204
  • 20. routing helpersbasic# config/routes.coffeemap.get posts, posts#publishedmap.get admin/posts, posts#allmap.post admin/posts, posts#createmap.get admin/posts/:id, posts#showmap.put admin/posts/:id, posts#modifymap.del admin/posts/:id, posts#destroyevolved# generate standard CRUD routesmap.resources posts# Link directly to controller with the right namemap.all :controller/:actionmap.all :controller/:action/:id
  • 21. namespacesmap.get posts, posts#publishedmap.namespace admin, -> map.get posts, posts#all map.post posts, posts#create map.get posts/:id, posts#show map.put posts/:id, posts#modify map.del posts/:id, posts#destroy
  • 22. moregenerators for controllersSoon: custom generators  Soon: custom structure  + a lof of features if you want to make UIs
  • 23. a talk by...contact@cozycloud.cchttps://blog.cozycloud.cchttps://twitter.com/mycozycloudCrédits photos: blmiers2, Ethan AblemanLicense Creative Commons by-3.0

×