Code Monkey home page Code Monkey logo

sinatra-mongodb's Introduction

Dependency Status

Ruby/Sinatra code to access MongoDB

A simple Ruby code to access RethinkDB and perform CRUD actions. Also, the code has a 'real-time change feed' to get all changes in database.

Programming Language and libraries used

  • Ruby v2.4.1

Main libraries:

  • mongoid ~>6.2.0
  • sinatra ~>2.0.0
  • sinatra-contrib ~>2.0.0

Running the code with MongoDB in Docker

  • Start MongoDB container
$ docker run --name my-mongo -p 27017:27017 -d mongo
  • Insert some data via irb
$ irb
require './server'
Book.create_indexes  
Book.create(title:'Foundation', author:'Isaac Asimov', isbn:'0553293354')
Book.create(title:'Dune', author:'Frank Herbert', isbn:'0441172717')
Book.create(title:'Hyperion (Hyperion Cantos)', author:'Dan Simmons', isbn:'0553283685')
  • Clone this repository

  • Run repo code via Docker with

    1. docker build -t sinatra-mongo .
    2. docker run -d --name my-app-container -p 9292:9292 --link my-mongo:mongo sinatra-mongo
    3. Go to localhost:9292/api/v1/books (see more routes at server.rb)
    • Once started, it is possible to add/update/delete documents using cURL:

    curl -i -X POST -H "Content-Type: application/json" -d'{"title":"The Power Of Habit", "author":"Charles Duhigg", "isbn":"081298160X"}' http://localhost:9292/api/v1/books

sinatra-mongodb's People

Contributors

vinpereira avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.