play rest swagger and some google charts

I’ve got an article published in Linux Format issue 214 https://www.linuxformat.com/archivesabout Rest,Swagger and Play with a demo application using Google Charts to display a timeseries overtime. There are 2 demos, one tracking the share price of BT compared to FTSE 100 and the temperature difference between London and Darlington.

The share price information uses Yahoo’s YQL to query a source of stock quotes yahoo.finance.quotes.
stockprice_graph

The temperature information is available from Open Weather Map API
temperature_graph

The database for Play implementation is Sqlite. The play implementation is 2.4 as 2.5 was too fresh to support Swagger at the time. I wanted to show how easy it is to add Swagger annotations to a simple interface.
weather_api

Finally as it’s Play it was easy to deploy this to Heroku. Albeit changing the database from Sqlite to Postgres. See
https://secure-retreat-29275.herokuapp.com/

and the 2 charts

Source code is available here
https://github.com/bernardjason/rest-swagger-app

weather chart
stock chart

blogdog, add foreign key constraint

I updated blogdog so that it shows sqlite within play framework using a foreign key. The trick is to get slick when it initialises to add the correct PRAGMA for sqlite. This is the value in application.conf

slick.dbs.default.db.connectionInitSql=”PRAGMA foreign_keys = ON”

then ensure db is created correctly (from evolutions 1.sql)

create table “BLOGS” (ID INTEGER PRIMARY KEY,USERS_ID INTEGER NOT NULL, USER VARCHAR NOT NULL,”WHEN” TIMESTAMP NOT NULL, WHAT VARCHAR NOT NULL , FOREIGN KEY(USERS_ID) REFERENCES USERS(ID));

note that foreign key cannot be a string value

full source is here https://github.com/bernardjason/blogdog