Giter VIP home page Giter VIP logo

back-your-future's Introduction

Back your future

A CRUD REST API with Heroku and Spark, and a free database with mLab and KMongo

This repository is a use-case of the following steps:

Create a server-app on Heroku:

When logged, click on "Create a new app..."

Set the remote repository for the project:

$ heroku git:remote -a name-of-the-heroku-app

Create a database and a user database on mLab:

Get the MongoDB URI on database's dashboard, then set the keys in MongoDb.kt of the project:

private const val DB_USER = ""
private const val DB_PASS = ""
private const val DB_NAME = ""

private const val DB_URI = "mongodb://$DB_USER:[email protected]:00000/$DB_NAME"

Mongo will automatically create the custom models (see PilotModel and CarModel).

Create the CRUD routes using Spark

BaseRoute for generics routes, PilotRoute and CarRoute for specific ones.

get("") { req, res ->  }
get("/:id") { req, res ->  }
post("") { req, res ->  }
put("/:id") { req, res ->  }
delete("/:id") { req, res ->  }

Create the DAO with KMongo:

BaseDAO for main requests. Particular requests from PilotDao or CarDao.

fun getAll(): String = getCollection().find().into(mutableListOf<T>()).toJson()
fun get(id: String): String = getCollection().findOneById(ObjectId(id)).toJson()

Use Postman or Insomnia to test the API


๐Ÿ’ฅ 88m/h reached!


Dr. Emmett Brown and Marty McFly are trapped in time.
They should go to the cloud to restart the DeLorean and get back to their timeline.
Will they succeed to easily create a server using Heroku, mLab, Spark and KMongo to go back home?


Dependencies used:

dependencies {
    compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.11'
    compile 'com.sparkjava:spark-kotlin:1.0.0-alpha'
    compile 'org.slf4j:slf4j-simple:1.7.12' // logger for Spark
    compile 'org.litote.kmongo:kmongo:3.9.0'
    compile 'com.google.code.gson:gson:2.2.4'
}

back-your-future's People

Contributors

gitdefllo avatar

Stargazers

Ken Fehling avatar Jean-Christophe MELIKIAN avatar

Watchers

James Cloos avatar  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.