SlideShare a Scribd company logo
1 of 21
Download to read offline
! 
! 
! 
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
 
504 syllabus sp 2010
504 syllabus sp 2010504 syllabus sp 2010
504 syllabus sp 2010loraevanouski
 
Plantilla metodologia activa webquest
Plantilla metodologia activa webquestPlantilla metodologia activa webquest
Plantilla metodologia activa webquestalacale70
 
Plantilla metodologia activa webquest
Plantilla metodologia activa webquestPlantilla metodologia activa webquest
Plantilla metodologia activa webquestalacale70
 
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
 
10 0320 ed_ forest hills board meeting
10 0320 ed_ forest hills board meeting10 0320 ed_ forest hills board meeting
10 0320 ed_ forest hills board meetingTom McGill
 
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 ModelsDickGlidden
 
Adventurer club manual
Adventurer club manualAdventurer club manual
Adventurer club manualSa Je La
 
Adventurer club manual
Adventurer club manualAdventurer club manual
Adventurer club manualSa 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 ConnectLAXConnectLAX
 
GRE Prep Handout - 4 sessions
GRE Prep Handout - 4 sessionsGRE Prep Handout - 4 sessions
GRE Prep Handout - 4 sessionsSuccess Prep
 
Mi BarHop Brand Plan
Mi BarHop Brand PlanMi BarHop Brand Plan
Mi BarHop Brand PlanNicole Sheard
 
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
 

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
 
504 syllabus sp 2010
504 syllabus sp 2010504 syllabus sp 2010
504 syllabus sp 2010
 
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
 
How Cross-Organizational Cooperation on AI lead to changes in Norway
How Cross-Organizational Cooperation on AI lead to changes in NorwayHow Cross-Organizational Cooperation on AI lead to changes in Norway
How Cross-Organizational Cooperation on AI lead to changes in Norway
 
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...
 
오피니언마이닝에 기반한 주식 자동 매매 시스템
오피니언마이닝에 기반한 주식 자동 매매 시스템오피니언마이닝에 기반한 주식 자동 매매 시스템
오피니언마이닝에 기반한 주식 자동 매매 시스템
 
10 0320 ed_ forest hills board meeting
10 0320 ed_ forest hills board meeting10 0320 ed_ forest hills board meeting
10 0320 ed_ forest hills board meeting
 
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
 
Mi BarHop Brand Plan
Mi BarHop Brand PlanMi BarHop Brand Plan
Mi BarHop Brand Plan
 
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
 

Recently uploaded

(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 

Recently uploaded (20)

Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 

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!!!! !