GithubHelp home page GithubHelp logo

dan-mcm / inspiration-api Goto Github PK

View Code? Open in Web Editor NEW
5.0 0.0 4.0 1.08 MB

☀️ API built with Scala & Play Framework. Uses Postgres & Slick

Scala 62.10% HTML 18.22% Shell 0.43% Batchfile 0.51% Dockerfile 4.17% TSQL 14.57%
inspiration inspirational-quotes api scala play

inspiration-api's Introduction

Inspiration API

An experimental API designed to improve my own skills at using both Scala and the Play Framework.

Running Locally

The service depends on the use of SBT and Docker.

Docker Setup

Launch a PSQL docker image exposed on port 5432

  • docker-compose up -d

Setup default tables automatically with provided script

  • psql -h localhost -U user inspiration_db -f dbsetup.sql

Note that the JDBC DB connection requires 2 env vars to be set:

  • DB_USER
  • DB_PASS

These will vary depending on your local postgres setup.

val connectionUrl = s"jdbc:postgresql://localhost:5432/inspiration_db?user=${sys.env("DB_USER")}&password=${sys.env("DB_PASS")}"

API Start

  • In one terminal run the command sbt run
  • In another terminal curl the inspiration endpoint: curl localhost:9000/inspiration

A basic html page is provided at the index route if you load up localhost:9000 in a browser you will see instructions for the available endpoints

Available Endpoints

GET

/inspiration - returns a single string containing a random quote featuring the author.

curl localhost:9000/inspiration

POST

/inspiration - adds post data to postgres DB - requires user to specify author and quote

curl -X POST -H 'Content-Type: application/json' -d '{"author": "dmcm", "quote": "quotation of the year"}' localhost:9000/inspiration

PUT

/inspiration - updates data in postgres DB - requires user to specify index, author and quote

curl -X PUT -H 'Content-Type: application/json' -d '{"index": 5, "author": "dmcm", "quote": "quotation of the year"}' localhost:9000/inspiration

DELETE

/inspiration/:index - deletes entry from postgres DB - requires user to specify index within url

curl -X DELETE localhost:9000/inspiration/6

Docker

The service can be run from a Docker container:

# build and tag image locally
docker build -t inspiration_api:v1 .

# port forwarding Docker to localhost:9000
docker run -ti -p 9000:9000 --network="host" <docker-image-id>

# publish docker image to docker hub
docker push <docker-repo>

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.