SlideShare a Scribd company logo
! 
! 
! 
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!!
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 
2 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 
3 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 
4 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":!"punit239@gmail.com",! 
! "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 
5 of 21
Sample!Request:!! 
{! 
! 
!!!!! "username":!"punit239@gmail.com",! 
! "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 
6 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 
7 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 
8 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 
9 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 
10 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 
11 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 
12 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 
13 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 
14 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/Z 
5184296551182419870",! 
!!!!!!!!!!!!"method":!"DELETE"! 
!!!!!!!!}! 
!!!!]! 
}! 
!! 
Project 2 – Tack On RESTful API 
15 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 
16 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 
17 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 
18 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 
19 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 
20 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! 
! 
Project 2 – Tack On RESTful API 
21 of 21 
! 
!! 
Traffic!this!time!!!! 
!

More Related Content

Similar to Tack On RESTful APIs - Pinterest Backend Simulation

GRE Prep Handout - 8 sessions
GRE Prep Handout - 8 sessionsGRE Prep Handout - 8 sessions
GRE Prep Handout - 8 sessionsSuccess Prep
 
Plantilla metodologia activa webquest
Plantilla metodologia activa webquestPlantilla metodologia activa webquest
Plantilla metodologia activa webquest
alacale70
 
Plantilla metodologia activa webquest
Plantilla metodologia activa webquestPlantilla metodologia activa webquest
Plantilla metodologia activa webquest
alacale70
 
Scott Williams Resume
Scott Williams ResumeScott Williams Resume
Scott Williams Resume
Scott Williams
 
Central California Writing Project Invitational Summer Institute: June 19-Jul...
Central California Writing Project Invitational Summer Institute: June 19-Jul...Central California Writing Project Invitational Summer Institute: June 19-Jul...
Central California Writing Project Invitational Summer Institute: June 19-Jul...
Fred Mindlin
 
Mad venture program synopsis
Mad venture program synopsisMad venture program synopsis
Mad venture program synopsisAP DealFlow
 
Impacts of collaborative consumption on traditional industries: scenarios for...
Impacts of collaborative consumption on traditional industries: scenarios for...Impacts of collaborative consumption on traditional industries: scenarios for...
Impacts of collaborative consumption on traditional industries: scenarios for...David Chapuis
 
오피니언마이닝에 기반한 주식 자동 매매 시스템
오피니언마이닝에 기반한 주식 자동 매매 시스템오피니언마이닝에 기반한 주식 자동 매매 시스템
오피니언마이닝에 기반한 주식 자동 매매 시스템
Dongsam Byun
 
Short Term Risk From Long Term Models
Short Term Risk From Long Term ModelsShort Term Risk From Long Term Models
Short Term Risk From Long Term Models
DickGlidden
 
Adventurer club manual
Adventurer club manualAdventurer club manual
Adventurer club manualSa Je La
 
Adventurer club manual
Adventurer club manualAdventurer club manual
Adventurer club manual
Sa Je La
 
CHERISE MARTIN FINaL 1809856
CHERISE MARTIN FINaL 1809856CHERISE MARTIN FINaL 1809856
CHERISE MARTIN FINaL 1809856Cherise Martin
 
Rackspace Cloud Monitoring - Strata NYC
Rackspace Cloud Monitoring - Strata NYCRackspace Cloud Monitoring - Strata NYC
Rackspace Cloud Monitoring - Strata NYCgdusbabek
 
Lacrosse Recruiting Guide by ConnectLAX
Lacrosse Recruiting Guide by ConnectLAXLacrosse Recruiting Guide by ConnectLAX
Lacrosse Recruiting Guide by ConnectLAX
ConnectLAX
 
GRE Prep Handout - 4 sessions
GRE Prep Handout - 4 sessionsGRE Prep Handout - 4 sessions
GRE Prep Handout - 4 sessionsSuccess Prep
 
Future of Testing Automation and QA - Anand Bagmar, ThoughtWorks
Future of Testing Automation and QA - Anand Bagmar, ThoughtWorksFuture of Testing Automation and QA - Anand Bagmar, ThoughtWorks
Future of Testing Automation and QA - Anand Bagmar, ThoughtWorksThoughtworks
 
3. javascript bangla tutorials
3. javascript bangla tutorials3. javascript bangla tutorials
3. javascript bangla tutorials
SEOPROFFESSIONALDIGI
 
6 hsdpa
6 hsdpa6 hsdpa
6 hsdpa
Abd Yehia
 
Reference_Letter_From_Nick
Reference_Letter_From_NickReference_Letter_From_Nick
Reference_Letter_From_NickShiqi Zhang
 
Assets or Liabilities - The Need to Implement Fair Regulatory Valuations for ...
Assets or Liabilities - The Need to Implement Fair Regulatory Valuations for ...Assets or Liabilities - The Need to Implement Fair Regulatory Valuations for ...
Assets or Liabilities - The Need to Implement Fair Regulatory Valuations for ...hughgrant
 

Similar to Tack On RESTful APIs - Pinterest Backend Simulation (20)

GRE Prep Handout - 8 sessions
GRE Prep Handout - 8 sessionsGRE Prep Handout - 8 sessions
GRE Prep Handout - 8 sessions
 
Plantilla metodologia activa webquest
Plantilla metodologia activa webquestPlantilla metodologia activa webquest
Plantilla metodologia activa webquest
 
Plantilla metodologia activa webquest
Plantilla metodologia activa webquestPlantilla metodologia activa webquest
Plantilla metodologia activa webquest
 
Scott Williams Resume
Scott Williams ResumeScott Williams Resume
Scott Williams Resume
 
Central California Writing Project Invitational Summer Institute: June 19-Jul...
Central California Writing Project Invitational Summer Institute: June 19-Jul...Central California Writing Project Invitational Summer Institute: June 19-Jul...
Central California Writing Project Invitational Summer Institute: June 19-Jul...
 
Mad venture program synopsis
Mad venture program synopsisMad venture program synopsis
Mad venture program synopsis
 
Impacts of collaborative consumption on traditional industries: scenarios for...
Impacts of collaborative consumption on traditional industries: scenarios for...Impacts of collaborative consumption on traditional industries: scenarios for...
Impacts of collaborative consumption on traditional industries: scenarios for...
 
오피니언마이닝에 기반한 주식 자동 매매 시스템
오피니언마이닝에 기반한 주식 자동 매매 시스템오피니언마이닝에 기반한 주식 자동 매매 시스템
오피니언마이닝에 기반한 주식 자동 매매 시스템
 
Short Term Risk From Long Term Models
Short Term Risk From Long Term ModelsShort Term Risk From Long Term Models
Short Term Risk From Long Term Models
 
Adventurer club manual
Adventurer club manualAdventurer club manual
Adventurer club manual
 
Adventurer club manual
Adventurer club manualAdventurer club manual
Adventurer club manual
 
CHERISE MARTIN FINaL 1809856
CHERISE MARTIN FINaL 1809856CHERISE MARTIN FINaL 1809856
CHERISE MARTIN FINaL 1809856
 
Rackspace Cloud Monitoring - Strata NYC
Rackspace Cloud Monitoring - Strata NYCRackspace Cloud Monitoring - Strata NYC
Rackspace Cloud Monitoring - Strata NYC
 
Lacrosse Recruiting Guide by ConnectLAX
Lacrosse Recruiting Guide by ConnectLAXLacrosse Recruiting Guide by ConnectLAX
Lacrosse Recruiting Guide by ConnectLAX
 
GRE Prep Handout - 4 sessions
GRE Prep Handout - 4 sessionsGRE Prep Handout - 4 sessions
GRE Prep Handout - 4 sessions
 
Future of Testing Automation and QA - Anand Bagmar, ThoughtWorks
Future of Testing Automation and QA - Anand Bagmar, ThoughtWorksFuture of Testing Automation and QA - Anand Bagmar, ThoughtWorks
Future of Testing Automation and QA - Anand Bagmar, ThoughtWorks
 
3. javascript bangla tutorials
3. javascript bangla tutorials3. javascript bangla tutorials
3. javascript bangla tutorials
 
6 hsdpa
6 hsdpa6 hsdpa
6 hsdpa
 
Reference_Letter_From_Nick
Reference_Letter_From_NickReference_Letter_From_Nick
Reference_Letter_From_Nick
 
Assets or Liabilities - The Need to Implement Fair Regulatory Valuations for ...
Assets or Liabilities - The Need to Implement Fair Regulatory Valuations for ...Assets or Liabilities - The Need to Implement Fair Regulatory Valuations for ...
Assets or Liabilities - The Need to Implement Fair Regulatory Valuations for ...
 

Recently uploaded

Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
veerababupersonal22
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 

Recently uploaded (20)

Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 

Tack On RESTful APIs - Pinterest Backend Simulation

  • 1. ! ! ! 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!!
  • 2. 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 2 of 21
  • 3. 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 3 of 21
  • 4. 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 4 of 21
  • 5. 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":!"punit239@gmail.com",! ! "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 5 of 21
  • 6. Sample!Request:!! {! ! !!!!! "username":!"punit239@gmail.com",! ! "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 6 of 21
  • 7. 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 7 of 21
  • 8. 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 8 of 21
  • 9. 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 9 of 21
  • 10. !!!!!!!!!!!!"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 10 of 21
  • 11. 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 11 of 21
  • 12. 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 12 of 21
  • 13. 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 13 of 21
  • 14. 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 14 of 21
  • 15. 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/Z 5184296551182419870",! !!!!!!!!!!!!"method":!"DELETE"! !!!!!!!!}! !!!!]! }! !! Project 2 – Tack On RESTful API 15 of 21
  • 16. 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 16 of 21
  • 17. !!!!!!!!"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 17 of 21
  • 18. 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 18 of 21
  • 19. 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 19 of 21
  • 20. 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 20 of 21
  • 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! ! Project 2 – Tack On RESTful API 21 of 21 ! !! Traffic!this!time!!!! !