21
CMPE& 275: Enterprise Application Development (Section 01) Professor: John Gash Project: Tack On RESTful APIs Group 5 Archit Agarwal (008065434) Akshay Bapat (008020571) Akshay Wattal (008941816) Punit Sharma (009268532) Shashank Garg (009310418) 05/12/2014

Tack On RESTful APIs - Pinterest Backend Simulation

Embed Size (px)

Citation preview

!!

!

CMPE&!275:!Enterprise!Application!Development!

(Section!01)!

Professor:!John!Gash!

!

Project:!Tack!On!RESTful!APIs!

!Group!5!

Archit!Agarwal!(008065434)!Akshay!Bapat!(008020571)!Akshay!Wattal!(008941816)!Punit!Sharma!(009268532)!Shashank!Garg!(009310418)!

!05/12/2014!!

Akshay Wattal
Akshay Wattal
Akshay Wattal
Akshay Wattal
Akshay Wattal
Akshay Wattal
Akshay Wattal

Project 2 – Tack On RESTful API

2 of 21

Table!of!Contents!Table of Contents ................................................................................................ 2

Introduction: ......................................................................................................... 3

Implementation Architecture .............................................................................. 4

API List ................................................................................................................. 5

Securing the API’s ............................................................................................. 18

Storing MIME, Images for pins in our case ..................................................... 18

Database Used ................................................................................................... 19

Appendix: ........................................................................................................... 20 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Project 2 – Tack On RESTful API

3 of 21

Introduction:!!

Project!TackOn!is!a!RESTful!service!to!which!a!user!can!perform!all!the!CRUD!operations!that! are! provided! by! Pinterest.! The! project! is! developed! in! Ruby,! using! Sinatra!micro!framework!and!Rack!server.!CouchDB!has!been!used!as!the!database.!Some!of!the!basic!functionalities!on!which!the!project!focuses!are!user!signup,!login,!Board!and!Pin!CRUD!operations,!and!post/delete!comments.!!Postman!has!been!used!as!the!HTTP!client!for!successfully!testing!the!RESTful!service.!!Pinterest!!Pinterest!is!a!tool!that!is!used!to!store!information!regarding!various!ideas!that!!people!come!up!with!associated!to!their!work!and!interests.!Users!can!create!and!share!boards!and!add!pins!to!every!board.!Each!user!can!follow!every!other!user!and!can!comment!on!the!boards!created!by!the!user!being!followed.!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!

Project 2 – Tack On RESTful API

4 of 21

Implementation!Architecture!!

We!have!implemented!the!system!architecture!as!the!figure!above.!We!have!chosen!a!dedicated!Master!node!to!be!the!recipient!of!all!incoming!client!requests,!and!forward!them!to!the!respective!slave!nodes.!Also,! for! the!sake!of!ensuring!atomic!consistency,!we! have! a! shared! database!where!we! use! the! client! and! domain! data.! The!Master’s!primary!role!is!to!serve!as!a!load!balancer,!to!help!keep!the!overall!system!healthy!and!well!balanced!in!terms!of!load.!!!

!

Project 2 – Tack On RESTful API

5 of 21

API!List!Below!are!a!list!of!15!API’s!that!are!created!for!providing!different!User,!Board,!Pin!and!Comment!functionality!for!this!Tack!On!project.!!

1. User!Sign&Up!API!This!API!enables!user!to!sign!up!with!the!system.!The!EmailID!of!the!user!acts!as!a!unique!identifier!for!signZup.!!End!Point!URL:!/users/signup!Response!Codes:!201,!400!Method:!POST!Sample!Request:!!{!! !! "firstName":!"Punit",!! "lastName":!"Sharma",!!!!! !"emailId":!"[email protected]",!! "password":!"password"!}!

!Sample!Response:!!{!!!!!"links":![!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/login",!!!!!!!!!!!!!"method":!"POST"!!!!!!!!!}!!!!!]!}!!!

2. User!Log&In!API!This! API! allows! a! user! to! login! to! the! system! given! valid! login! credentials! are!provided.!Credentials!are!then!checked!with!the!existing!user!information!in!the!database,!after!which!cookies!are!generated!and!sent!back!as!response.!!End!Point!URL:!/users/login!Response!Codes:!201,!400!Method:!POST!

!!!!

!

Project 2 – Tack On RESTful API

6 of 21

Sample!Request:!!{!!!!!!! "username":!"[email protected]",!! "password":!"password"!}!

!Sample!Response:!!{!!!!!"links":![!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards",!!!!!!!!!!!!!"method":!"GET"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards",!!!!!!!!!!!!!"method":!"POST"!!!!!!!!!}!!!!!]!}!

!3. User!Board!Creation!and!Read!All!Boards!API!

This!API!enables!an!authenticated!user!to!create!a!board!where!pins!can!be!added.!By!default!boards!are!created!as!public!boards.!This!also!allows!for!getting!all!the!boards!of!a!particular!loggedZin!user.!!End!Point!URL:!/users/:user_id/boards!Parameter:!!:!user_id!–!This!is!system!generated!unique!user!identifier!Response!Codes:!!200,!201,!400!Method:!POST!

!Sample!Request:!!{!! "boardName":!"My!Books!Collection",!! "boardDesc":!"Collection!of!my!Fav!Books",!! "category":!"Books",!! "isPrivate":!"false"!}!!!!!!

Project 2 – Tack On RESTful API

7 of 21

Sample!Response:!!{!!!!!"links":![!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Books!Collection",!!!!!!!!!!!!!"method":!"GET"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Books!Collection",!!!!!!!!!!!!!"method":!"PUT"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Books!Collection",!!!!!!!!!!!!!"method":!"DELETE"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Books!Collection/pins",!!!!!!!!!!!!!"method":!"POST"!!!!!!!!!}!!!!!]!}!!Method:!GET!Sample!Request:!!N/A!Sample!Response:!!{!!!!!"Boards":![!!!!!!!!!{!!!!!!!!!!!!!"boardName":!"My!Books!Collection",!!!!!!!!!!!!!"boardDesc":!"Collection!of!my!Fav!Books",!!!!!!!!!!!!!"category":!"Books",!!!!!!!!!!!!!"isPrivate":!"false",!!!!!!!!!!!!!"pins":!null,!!!!!!!!!!!!!"type":!"Board"!!!!!!!!!}!!!!!]!}!!!!!!!!

Project 2 – Tack On RESTful API

8 of 21

4. User!Board!Management!APIs!These!set!of!APIs!are!for!User!Board!Read,!Update!and!Delete.!LoggedZin!users!having!proper!Cookies!can!use!these!boards!APIs.!!End!Point!URL:!/users/:user_id/boards/:board_name!Parameter:!!:!user_id!–!This!is!system!generated!unique!user!identifier!:!board_name!–!This!is!the!name!of!the!board!that!was!created!Response!Codes:!200,!400!Method:!GET!Sample!Request:!!N/A!

!Sample!Response:!!{!!!!!"board":!{!!!!!!!!!"boardName":!"My!Books!Collection",!!!!!!!!!"boardDesc":!"Collection!of!my!Fav!Books",!!!!!!!!!"category":!"Books",!!!!!!!!!"isPrivate":!"false",!!!!!!!!!"pins":!null,!!!!!!!!!"type":!"Board"!!!!!},!!!!!"links":![!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Books!Collection",!!!!!!!!!!!!!"method":!"PUT"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Books!Collection",!!!!!!!!!!!!!"method":!"DELETE"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Books!Collection/pins",!!!!!!!!!!!!!"method":!"POST"!!!!!!!!!}!!!!!]!}!!!!!!!!

Project 2 – Tack On RESTful API

9 of 21

Method:!PUT!Sample!Request:!!{!!! "boardDesc":!"Updated!Collection!of!my!Fav!Books"!!}!!Sample!Response:!!{!!!!!"board":!{!!!!!!!!!"boardName":!"My!Books!Collection",!!!!!!!!!"boardDesc":!"Updated!Collection!of!my!Fav!Books",!!!!!!!!!"category":!"Books",!!!!!!!!!"isPrivate":!"false",!!!!!!!!!"pins":!null,!!!!!!!!!"type":!"Board"!!!!!},!!!!!"links":![!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Books!Collection",!!!!!!!!!!!!!"method":!"GET"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Books!Collection",!!!!!!!!!!!!!"method":!"DELETE"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Books!Collection/pins",!!!!!!!!!!!!!"method":!"POST"!!!!!!!!!}!!!!!]!}!!Method:!DELETE!Sample!Request:!N/A!!Sample!Response:!!{!!!!!"links":![!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/&1599838316006455160/boards",!!!!!!!!!!!!!"method":!"GET"!!!!!!!!!},!!!!!!!!!{!

Project 2 – Tack On RESTful API

10 of 21

!!!!!!!!!!!!"url":!"/users/&1599838316006455160/boards",!!!!!!!!!!!!!"method":!"POST"!!!!!!!!!}!!!!!]!}!!

!5. PIN!Creation!and!Read!all!PINs!

This!API!allows!for!creation!of!a!single!pin!on!a!board.!In!addition,!it!allows!for!the!capability!to!read!all!the!pins.!!End!Point!URL:!/users/:user_id/boards/:board_name/pins!Parameter:!!:!user_id!–!This!is!system!generated!unique!user!identifier!:!board_name!–!This!is!the!name!of!the!board!that!was!created!Response!Codes:!200,!201,!400!Method:!POST!Sample!Request:!!Big!Request!for!document!with!Image!Binary!details!!Sample!Response:!!{!!!!!"links":![!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3",!!!!!!!!!!!!!"method":!"GET"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3",!!!!!!!!!!!!!"method":!"PUT"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3",!!!!!!!!!!!!!"method":!"DELETE"!!!!!!!!!}!!!!!]!}!!!!!!

Project 2 – Tack On RESTful API

11 of 21

Method:!GET!Sample!Request:!N/A!!Sample!Response:!!{!!!!!"pins":![!!!!!!!!!{!!!!!!!!!!!!!"_id":!"467cc721daca012fa15494631b2035c3",!!!!!!!!!!!!!"pinName":!"CouchDB",!!!!!!!!!!!!!"image":!"CouchDB",!!!!!!!!!!!!!"attachments":!"http://127.0.0.1:5984/pint/467cc721daca012fa15494631b2035c3/img.png",!!!!!!!!!!!!!"description":!"Best!Band!Ever",!!!!!!!!!!!!!"comments":!null,!!!!!!!!!!!!!"_rev":!"1Zb62c9bc4f6e6663745ab776678ff332e",!!!!!!!!!!!!!"_attachments":!{!!!!!!!!!!!!!!!!!"img.png":!{!!!!!!!!!!!!!!!!!!!!!"content_type":!"image/png",!!!!!!!!!!!!!!!!!!!!!"revpos":!1,!!!!!!!!!!!!!!!!!!!!!"digest":!"md5Zw+7EUyBZq+3CQs6L7NI3rQ==",!!!!!!!!!!!!!!!!!!!!!"length":!7941,!!!!!!!!!!!!!!!!!!!!!"stub":!true!!!!!!!!!!!!!!!!!}!!!!!!!!!!!!!}!!!!!!!!!}!!!!!]!}!

!!

6. PIN!Management!APIs!These!set!of!APIs!are!for!PIN!Read,!Update!and!Delete.!LoggedZin!users!having!proper!Cookies!can!use!these!pin!management!APIs.!!End!Point!URL:!/users/:user_id/boards/:board_name/pins/:pin_id!Parameter:!!:!user_id!–!This!is!system!generated!unique!user!identifier!:!board_name!–!This!is!the!name!of!the!board!that!was!created!:!pin_id!–!This!is!the!system!generated!unique!pin!identifier!Response!Codes:!200,!400!Method:!GET!!!!!

Project 2 – Tack On RESTful API

12 of 21

Sample!Request:!N/A!!Sample!Response:!!{!!!!!"pin":!{!!!!!!!!!"_id":!"467cc721daca012fa15494631b2035c3",!!!!!!!!!"pinName":!"CouchDB",!!!!!!!!!"image":!"CouchDB",!!!!!!!!!"attachments":!"http://127.0.0.1:5984/pint/467cc721daca012fa15494631b2035c3/img.png",!!!!!!!!!"description":!"Best!Band!Ever",!!!!!!!!!"comments":!null,!!!!!!!!!"_rev":!"1Zb62c9bc4f6e6663745ab776678ff332e",!!!!!!!!!"_attachments":!{!!!!!!!!!!!!!"img.png":!{!!!!!!!!!!!!!!!!!"content_type":!"image/png",!!!!!!!!!!!!!!!!!"revpos":!1,!!!!!!!!!!!!!!!!!"digest":!"md5Zw+7EUyBZq+3CQs6L7NI3rQ==",!!!!!!!!!!!!!!!!!"length":!7941,!!!!!!!!!!!!!!!!!"stub":!true!!!!!!!!!!!!!}!!!!!!!!!}!!!!!},!!!!!"links":![!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3",!!!!!!!!!!!!!"method":!"PUT"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3",!!!!!!!!!!!!!"method":!"DELETE"!!!!!!!!!}!!!!!]!}!!Method:!PUT!Sample!Request:!!{!!!!!!!!"pinName":!"Updated!CouchDB"!!}!!

Project 2 – Tack On RESTful API

13 of 21

Sample!Response:!!{!!!!!"pin":!{!!!!!!!!!"_id":!"467cc721daca012fa15494631b2035c3",!!!!!!!!!"pinName":!"Updated!CouchDB",!!!!!!!!!"image":!"CouchDB",!!!!!!!!!"attachments":!"http://127.0.0.1:5984/pint/467cc721daca012fa15494631b2035c3/img.png",!!!!!!!!!"description":!"Best!Band!Ever",!!!!!!!!!"comments":!null,!!!!!!!!!"_rev":!"2Z777ddd57adf7a6e15069c53c17a33e2b",!!!!!!!!!"_attachments":!{!!!!!!!!!!!!!"img.png":!{!!!!!!!!!!!!!!!!!"content_type":!"image/png",!!!!!!!!!!!!!!!!!"revpos":!1,!!!!!!!!!!!!!!!!!"digest":!"md5Zw+7EUyBZq+3CQs6L7NI3rQ==",!!!!!!!!!!!!!!!!!"length":!7941,!!!!!!!!!!!!!!!!!"stub":!true!!!!!!!!!!!!!}!!!!!!!!!}!!!!!},!!!!!"links":![!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3",!!!!!!!!!!!!!"method":!"GET"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3",!!!!!!!!!!!!!"method":!"DELETE"!!!!!!!!!}!!!!!]!}!!!!!!!!!!!

Project 2 – Tack On RESTful API

14 of 21

Method:!DELETE!Sample!Request:!N/A!!!Sample!Response:!!{!!!!!"links":![!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z806136442321055063/boards/My!Books!Collection",!!!!!!!!!!!!!"method":!"GET"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z806136442321055063/boards/My!Books!Collection",!!!!!!!!!!!!!"method":!"PUT"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z806136442321055063/boards/My!Books!Collection",!!!!!!!!!!!!!"method":!"DELETE"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z806136442321055063/boards/My!Books!Collection/pins",!!!!!!!!!!!!!"method":!"POST"!!!!!!!!!}!!!!!]!}!!

7. Create!Comment!on!Pin!API!This!API!allows!for!creation!of!a!single!comment!on!a!pin.!In!addition,!it!allows!for!the!capability!to!read!all!comments!on!the!pin.!!End!Point!URL:!/users/:user_id/boards/:board_name/pins/:pin_id/comment!Parameter:!!:!user_id!–!This!is!system!generated!unique!user!identifier!:!board_name!–!This!is!the!name!of!the!board!that!was!created!:!pin_id!–!This!is!the!system!generated!unique!pin!identifier!Response!Codes:!200,!201,!400!Method:!POST!

!Sample!Request:!!{!!!!!!!!"description":!"I!love!this!Band"!!}!!!

Project 2 – Tack On RESTful API

15 of 21

Sample!Response:!!{!!!!!"pin":!{!!!!!!!!!"_id":!"467cc721daca012fa15494631b2035c3",!!!!!!!!!"pinName":!"Updated!CouchDB",!!!!!!!!!"image":!"CouchDB",!!!!!!!!!"attachments":!"http://127.0.0.1:5984/pint/467cc721daca012fa15494631b2035c3/img.png",!!!!!!!!!"description":!"Best!Band!Ever",!!!!!!!!!"comments":![!!!!!!!!!!!!!{!!!!!!!!!!!!!!!!!"_id":!"Z5184296551182419870",!!!!!!!!!!!!!!!!!"description":!"I!love!this!Band",!!!!!!!!!!!!!!!!!"user_id":!"Z1599838316006455160",!!!!!!!!!!!!!!!!!"type":!"Comment"!!!!!!!!!!!!!}!!!!!!!!!],!!!!!!!!!"_rev":!"3Z94f338511981e3d924a70f9286511b33",!!!!!!!!!"_attachments":!{!!!!!!!!!!!!!"img.png":!{!!!!!!!!!!!!!!!!!"content_type":!"image/png",!!!!!!!!!!!!!!!!!"revpos":!1,!!!!!!!!!!!!!!!!!"digest":!"md5Zw+7EUyBZq+3CQs6L7NI3rQ==",!!!!!!!!!!!!!!!!!"length":!7941,!!!!!!!!!!!!!!!!!"stub":!true!!!!!!!!!!!!!}!!!!!!!!!}!!!!!},!!!!!"links":![!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3/comment/",!!!!!!!!!!!!!"method":!"GET"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3/comment/Z5184296551182419870",!!!!!!!!!!!!!"method":!"DELETE"!!!!!!!!!}!!!!!]!}!!!

Project 2 – Tack On RESTful API

16 of 21

Method:!GET!Sample!Request:!N/A!

!Sample!Response:!{!!!!!"comments":![!!!!!!!!!{!!!!!!!!!!!!!"_id":!"Z5184296551182419870",!!!!!!!!!!!!!"description":!"I!love!this!Band",!!!!!!!!!!!!!"user_id":!"Z1599838316006455160",!!!!!!!!!!!!!"type":!"Comment"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"_id":!"Z6544717492908941456",!!!!!!!!!!!!!"description":!"Awesome!Band",!!!!!!!!!!!!!"user_id":!"Z1599838316006455160",!!!!!!!!!!!!!"type":!"Comment"!!!!!!!!!}!!!!!]!}!

!8. Delete!Comment!API!

This!API!allows!for!delete!of!a!single!comment!on!a!pin.!!End!Point!URL:!/users/:user_id/boards/:board_name/pins/:pin_id/comment/:comment_id!Parameter:!!:!user_id!–!This!is!system!generated!unique!user!identifier!:!board_name!–!This!is!the!name!of!the!board!that!was!created!:!pin_id!–!This!is!system!generated!unique!pin!identifier!:!comment_id!–!This!is!system!generated!unique!comment!identifier!Response!Codes:!200,!400!Method:!DELETE!Sample!Request:!!!Sample!Response:!!{!!!!!"pin":!{!!!!!!!!!"_id":!"467cc721daca012fa15494631b2035c3",!!!!!!!!!"pinName":!"Updated!CouchDB",!!!!!!!!!"image":!"CouchDB",!!!!!!!!!"attachments":!"http://127.0.0.1:5984/pint/467cc721daca012fa15494631b2035c3/img.png",!!!!!!!!!"description":!"Best!Band!Ever",!

Project 2 – Tack On RESTful API

17 of 21

!!!!!!!!"comments":![!!!!!!!!!!!!!{!!!!!!!!!!!!!!!!!"_id":!"Z6544717492908941456",!!!!!!!!!!!!!!!!!"description":!"Awesome!Band",!!!!!!!!!!!!!!!!!"user_id":!"Z1599838316006455160",!!!!!!!!!!!!!!!!!"type":!"Comment"!!!!!!!!!!!!!}!!!!!!!!!],!!!!!!!!!"_rev":!"5Z46b3de6ec1c7e1b7b2a7f87e8f2cbfd6",!!!!!!!!!"_attachments":!{!!!!!!!!!!!!!"img.png":!{!!!!!!!!!!!!!!!!!"content_type":!"image/png",!!!!!!!!!!!!!!!!!"revpos":!1,!!!!!!!!!!!!!!!!!"digest":!"md5Zw+7EUyBZq+3CQs6L7NI3rQ==",!!!!!!!!!!!!!!!!!"length":!7941,!!!!!!!!!!!!!!!!!"stub":!true!!!!!!!!!!!!!}!!!!!!!!!}!!!!!},!!!!!"links":![!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3",!!!!!!!!!!!!!"method":!"GET"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3",!!!!!!!!!!!!!"method":!"PUT"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3",!!!!!!!!!!!!!"method":!"POST"!!!!!!!!!},!!!!!!!!!{!!!!!!!!!!!!!"url":!"/users/Z1599838316006455160/boards/My!Music!Collection/pins/467cc721daca012fa15494631b2035c3/comment/",!!!!!!!!!!!!!"method":!"POST"!!!!!!!!!}!!!!!]!}!

Project 2 – Tack On RESTful API

18 of 21

Securing!the!API’s! We!have!implemented!the!cookie!approach!to!authenticate!the!requests.!!When!a!user!logs!in!we!generate!a!cookie,!which!is!the!hash!of!username!and!password,!store!it!in!our!keyZvalue!store!and!set!the!cookie!and!send!it!in!the!response.!!The!setZcookie!method!is!provided!in!the!Sinatra!framework.!!response.set_cookie("pint_cookie",!:value!=>!hash.to_s!,!!!!!!!!!!!!!!!!!!!!!!!!!!!:domain!=>!{IP!of!our!node},!!!!!!!!!!!!!!!!!!!!!!!!!!!:path!=>!'/'!!!!!!!!!!!!!!!!!!!!!!!!!!!)!!Before!each!request!for!the!API!we!are!authenticate!on!the!basis!of!the!cookie,!the!user!agents! sends.! Whether! a! request! is! authenticated! or! not! is! checked! in! the! before!sections!of!the!main!application!class!and!a!variable! is!set! if! the!cookie! is!there! in!our!CouchDB.! ! This! variable! further! forms! the!basis!of!whether! access! should!be! given! to!API.!!

halt(401,'Not!Authorized')!unless!auth!!The!above!line!of!code!blocks!the!access!if!the!auth!if!false.!

Storing!MIME,!Images!for!pins!in!our!case!!We! had! the! choice! to! store! the! images! in! file! system! and! specify! the! path! in! the!database!or!directly!store!the!images!in!CouchDB.!!We! went! with! the! approach! to! store! images! directly! into! the! DB! and! use! the!sophisticated! replication!of!CouchDB! to!do!away!with!backing!up! file! server!and! their!replication!and!synching!problems.!!The!image!is!stored!into!the!database!by!providing! inside!the!JSON!request!a!field!the!binary!data!called!_attachments.!The!binary!data!is!stored!and!can!be!retrieved!as!the!mime!type!it!is!originally!saved!as.!!!

Project 2 – Tack On RESTful API

19 of 21

Database!Used! CouchDB! is! used! as! database,! which! is! a! NoSql! document! oriented! database! where!every! document! has! certain! characteristics.! Advantages! with! CouchDB! are,! memory!consumption!is!less,!there!are!no!read!blocks!and!offers!flexible!schema!design,!fast!and!agile! CRUD! operations,! images! and! files! can! be! saved! directly.! The! schema! design!implemented!for!our!project!is!as!under:! User!Schema:!!{!

firstName!:!String!lastName!:!String!emailId!:!String!password!:!String!_id!:!String!user_id!:!String!boards!:![{!

boardName!:!String!boardDesc!:!String!category!:!String!isPrivate!:!String!pins!:!Set!//!for!all!pins!of!this!board!}]!

}! Pin!Schema:!!{!

_id!:!String!pinName!:!String!image!:!String!attachments!:!String!description!:!String!comments!:![{!

_id!:!String!description!:!String!user_id!:!String!}]!

!}!!

!

Project 2 – Tack On RESTful API

20 of 21

Appendix:!!Ruby!Ruby!is!among!the!top!10!popular!programming!languages!worldwide.! It! is!completely!free! to! use! and!modify.! Ruby! treats! everything! as! an! object! and! every! object! can! be!provided! with! its! own! properties! and! actions.! Properties! are! known! as! the! instance!variables!while!the!actions!are!known!as!methods.!Ruby!is!a!very!flexible!language!and!allows!all!its!users!to!alter!parts;!remove,!redefine!and!add!to!the!essential!and!existing!parts.!!RubyGems!RubyGems!is!a!package!manager!for!Ruby!language!and!provides!a!format!for!installing!ruby!applications!and!their!libraries.!They!are!easily!to!install!and!manage.!!!Inside!a!gem!are!the!following!contents:!•!Code!•!Documentation!•!gemspec!!Sinatra!Sinatra! is! an! open! source!micro! framework! application! and! domain! specific! language!used!with! ruby.! It! is! like! the! other! ruby! frameworks! like! Rails,! Nitro! and! camping.! It!comes!with!Rack!server!and!also!supports!Thin!server.!It!is!a!very!flexible!framework!and!require!the!model!view!controller!pattern!to!be!followed!every!time.!!Rack!Rack! is!an! interface!between!web!servers!and!ruby! frameworks.!While!using!Rack! the!user! needs! to! provide! an! 'app'! object! that! gives! a! response! to! the! call! method! and!returns!an!array!with!following!elements:!!•!HTTP!response!•!Headers!•!Response!body!!CouchDB!CouchDB!is!the!database!that!stores!all!the!data!with!JSON!documents.!One!can!access!the!data!by!querying!using!the!web!browser!through!HTTP!request.!The!documents!can!be! transformed!with! the! help! of! JavaScript.! There! are! various! features! that! CouchDB!comes!with!like!on!the!fly!document!transformation!and!real!time!change!notifications.!!!!!

Project 2 – Tack On RESTful API

21 of 21

Postman!Postman!is!an!HTTP!client!used!for!efficiently!and!successfully!testing!the!RESTful!web!services.!It!saves!all!the!requests!that!are!made!to!the!web!service!for!future!use.!It!is!capable!of!making!every!method!request!like,!GET,!POST,!PUT!and!DELETE.!!

!GitHub!Repository!Details!!Project!URL:!https://github.com/oldmonk7/pinterest275!!

!!!

Traffic!this!time!!!!!