SlideShare a Scribd company logo
CMPE 275
Project 2 Report
RESTful social collaboration through Pinterest re-enactment
Team:
Bhushan Deo (009269403)
Deven Pawar (009275994)
Dhruv Gogna (005067284)
Gaurav Bhardwaj (009297431)
Vinay Bhore (009290931)
Introduction
The main goal of Project 2 is to explore the design and challenges in developing RESTful web services for
a social media service such as Pinterest. Sharing content is an important pattern found in all social media
services. Providing robust and well documented web services is very important in such products as there
are several external clients which use them to access and manipulate stored user data. In this report, we
provide a detailed explanation of our team’s design and implementation.
High Level Architecture
The team’s configuration consists of the following components:
1. Web Services:
We expose our functionality to the client using RESTful web services written in Python using the
Bottle micro-framework.
2. Database:
CouchDB NoSQL database is used to persist user data. It provides data storage as JSON
documents and thus naturally maps to the requirements. Also, when client hits our web service
and some data is changed, we can verify changes in the database through the web interface
(Futon), that comes with CouchDB.
3. couchdb-python library:
This library provides interface to interact with CouchDB from python code. In our experience,
this was a very well designed library with advanced features like high-level couchDB document
to python object mapping, intuitive interfaces and good documentation.
4. Client:
For testing, we are using curl to hit our web services and see the response. Curl provides many
advanced options to make testing via HTTP requests easy.
The following sections explain the functionalities implemented and the web service and database
component in detail. These include comments about what we learnt while working on each component.
Functionalities
This project also required cross team interaction to come up with a stable specification for the web
services. As per the specification agreed to by the class, following functionalities were implemented by
our team.
Here, we observed how the traditional Create, Read, Update and Delete operations in databases, map
exactly to HTTP methods POST, GET, PUT and DELETE respectively.
Functionality Endpoint (fields in angular brackets are generated on the
server)
CRUD? HTTP
Met-
hod
Request
Parameters (all
are string type
unless specified)
Sign up http://localhost:8080/users/signUp Create POST firstName
lastName
emailId
password
Login http://localhost:8080/users/login/ Create POST emailId
password
Create a
board
http://localhost:8080/users/<userId>/boards/ Create POST boardName
boardDesc
category
isPrivate(Boolean)
Get all
boards
http://localhost:8080/users/<userId>/boards/ Read GET None
Get details of
a single
board
http://localhost:8080/users/<userId>/boards/<boardId>/ Read GET None
Update
Board
http://localhost:8080/users/<userId>/boards/<boardId>/ Update PUT boardName
boardDesc
category
isPrivate(Boolean)
Delete Board http://localhost:8080/users/<userId>/boards/<boardId>/ Delete DELETE None
Create Pin http://localhost:8080/users/<userId>/boards/<boardId>/p
ins/
Create POST pinName
image
description
Get a single
pin from a
board
http://localhost:8080/users/<userId>/boards/<boardId>/p
ins/<pinId>/
Read GET None
Get all pins
from a board
http://localhost:8080/users/<userId>/boards/<boardId>/p
ins/
Read GET None
Update a pin http://localhost:8080/users/<userId>/boards/<boardId>/p
ins/<pinId>/
Update PUT pinName
image
description
Delete a pin http://localhost:8080/users/<userId>/boards/<boardId>/p
ins/<pinId>/
Delete DELETE None
Add a
comment to
a pin
http://localhost:8080/users/<userId>/boards/<boardId>/p
ins/<pinId>/comment/
Create POST description
View
comments
on a pin
http://localhost:8080/users/<userId>/boards/<boardId>/p
ins/<pinId>/comment/
Read GET None
The responses were returned in JSON format and contained relevant data and endpoint information for
subsequent operations as agreed to by the class.
Web Services
Why Web Services fit in this project?
Essentially, web services help de-couple the client and the server implementations. User performs
various CRUD operations on an external system by sending HTTP requests through the client. The web
service layer, intercepts these requests on the server, performs operations on the database and sends
back appropriate response to the client. This fits well with the sharing and collaboration required by
social media products. From real world examples such as Facebook, Twitter and Pinterest, it can be seen
that a robust and well documented RESTful API is a vital contributor to these products going viral.
Bottle:
Web services were written in Python using the Bottle micro-framework. We found Bottle to be very
intuitive for creating our web services. The framework is very lightweight and in order to use it, it only
requires us to include one bottle.py file in the project directory.
Server:
Bottle runs by default on a single threaded WSGI server, but has adapters to various multi-threaded
servers such as paste and Cherrypy which give better performance for applications that need to handle
large number of concurrent requests. For testing this project, we have used the default server.
Mapping requests to appropriate methods:
Various endpoints as mentioned in the functionalities section, map easily to corresponding methods
which process the requests at those endpoint, simply by placing a @route decorator above that method.
Retrieving data from request:
In REST, the URL path determines the data that will be accessed or manipulated and the HTTP method
determines the operation that will be performed on that data.
- To get information about data that will be accessed, we use wildcards in the URL:
@route(‘http://localhost:8080/users/<userId>/boards/<boardId>/’,method=’GET’)
def getBoard(userId, boardId):
# got userId and boardId from the URL, now perform GET(read) on database
- To retrieve data from the HTTP request, bottle provides convenient methods in the request object:
@route(‘http://localhost:8080/users/<userId>/boards/<boardId>/’,method=’PUT’)
def updateBoard(userId, boardId):
# got userId and boardId from the URL, now perform PUT(update)on database
# with the fields sent in the request by the client
boardName = request.forms.get('boardName')
boardDesc = request.forms.get('boardDesc')
Returning JSON response:
JSON was the decided as the format in which response will be sent back to the client. Even in this case,
Bottle made it easy to return back response with “application/json” content type. We simply had to
return a python dictionary object. Bottle returns the response in JSON and the appropriate field is set in
the HTTP header.
@route(‘http://localhost:8080/users/<userId>/boards/<boardId>/’,method=’PUT’)
def updateBoard(userId, boardId):
# perform appropriate operations
return dict(status='OK', message='sample message')
If other response types such as html or xml are expected by the client, we are aware that we would have
to check for the content types which the client accepts from the HTTP request header and accordingly
format the response before sending it back (content negotiation).
Handling trailing ‘/’ slash:
If some clients put a trailing slash at the end of the endpoint URL, then that is treated as a separate
route by Bottle and might not map to the appropriate method in our web service code. Given that we
would be testing across teams, this was highly probable. To handle this, Bottle documentation suggests
to simply map two routes to the same method, one with a trailing slash and one without a slash.
@route(‘http://localhost:8080/users/<userId>/boards/<boardId>/’,method=’PUT’)
#No trailing slash
@route(‘http://localhost:8080/users/<userId>/boards/<boardId>’,method=’PUT’)
def updateBoard(userId, boardId):
# perform appropriate operations
Database
In REST web services, we can think of the URL as a path that is traversed to get to the data that is to be
accessed or manipulated. Further, the HTTP method that is specified in the HTTP request gives us the
operation (create, read, update or delete) that is to be performed on the data. Accordingly the actions
that we take in code depend on the combination of the following factors:
1. Response format accepted by the client (json, xml, html, image, etc..)
2. Data that is to be accessed (URL traversal)
3. What kind of operation on the data (HTTP method type)
Thus, for every endpoint there are several combinations that need to be handled so that we process the
user request appropriately and so that we return desired response back to the user. In this context, it is
clear that we have to organize our data based on the endpoints that we expose to the user.
We observed that this is a notable difference compared to Project 1, where there was only one endpoint
for the client, and the server queue delegated the message to the appropriate resource to handle. In
Project 2, there are several endpoints for the client and each endpoint maps to one method on the server
side.
The flat schema that we have used to store data in CouchDB is as follows. The “_id” is the userId that is
generated server side when the user signs up. This is passed around in each URL and is used to identify
user in each subsequent request.
{
"_id": {
"firstName": "",
"lastName": "",
"emailId": "",
"password": "",
"isLoggedIn": false,
"boards": [
{
"boardId": "",
"boardName": "",
"boardDesc": "",
"category": "",
"isPrivate": "",
"pins": [
{
"pinId": "",
"pinName": "",
"image": "",
"description": "",
"comments": []
}
]
}
]
}
}
Drawback:
The limitation of this schema is that for any request, we get the entire complex document associated
with a userId from the database. Then, in case of long URLs we have to employ multiple nested loops to
get to the data that we require. For example, updating information about a pin needs three nested
loops through the document that is returned. This is shown in the figure above. This would be
problematic if a user had thousands of boards and pins.
A solution to this would be to create separate tables (“databases” in CouchDB) for each step in the
endpoint URL tree, i.e. separate tables for user, board and comments, each record containing reference
to the userId. However, the tradeoff here is that this would require more queries to the database per
user request.
Note on Aerospike:
Initially we decided on using Aerospike as our database. However, its Python client seems to be under
development and there was no support for list and map data structures. Further, there was no query
support in the Python client, only full table scan was supported. Hence we decided to go with CouchDB.
Nonetheless, it was interesting to understand Aerospike’s architecture and concepts such as location
awareness of client, peer relationship among nodes, use of binary wire protocol for communication and
cross data center replication.
Conclusion
For our team, following are the major learnings from this project:
1. Programming in Python
2. RESTful web services
3. Database design for RESTful web services
4. Micro-frameworks
5. Comparison of technologies used in Project 1 and 2
6. CouchDB and Aerospike
7. Collaboration in Small and Large Software Development Teams

More Related Content

What's hot

A presentation on WCF & REST
A presentation on WCF & RESTA presentation on WCF & REST
A presentation on WCF & RESTSanthu Rao
 
Ch06 edge transport
Ch06 edge transportCh06 edge transport
Ch06 edge transport
Shane Flooks
 
Integration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud FoundryIntegration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud Foundry
Joshua Long
 
Ch05 high availability
Ch05 high availabilityCh05 high availability
Ch05 high availability
Shane Flooks
 
Mule splitters
Mule splittersMule splitters
Mule splitters
Ravinder Singh
 
Splitters in mule
Splitters in muleSplitters in mule
Splitters in mule
vasanthii9
 
Networking in java, Advanced programming
Networking in java, Advanced programmingNetworking in java, Advanced programming
Networking in java, Advanced programming
Gera Paulos
 
Remoting and serialization
Remoting and serializationRemoting and serialization
Remoting and serialization
Chathurangi Shyalika
 
Servlet basics
Servlet basicsServlet basics
Servlet basics
Santosh Dhoundiyal
 
Concurrency and parallel in .net
Concurrency and parallel in .netConcurrency and parallel in .net
Concurrency and parallel in .net
Mohammad Hossein Karami
 
Basic Networking in Java
Basic Networking in JavaBasic Networking in Java
Basic Networking in Java
suraj pandey
 
Websocket
WebsocketWebsocket
Websocket
艾鍗科技
 
Azure Service Bus Performance Checklist
Azure Service Bus Performance ChecklistAzure Service Bus Performance Checklist
Azure Service Bus Performance Checklist
Salim M Bhonhariya
 
Mule splitters
Mule splittersMule splitters
Mule splitters
Gandham38
 
Đề thi lý thuyết DWSJ Aptech
Đề thi lý thuyết DWSJ AptechĐề thi lý thuyết DWSJ Aptech
Đề thi lý thuyết DWSJ Aptech
Nhân Châu KP
 
Syer Monitoring Integration And Batch
Syer Monitoring Integration And BatchSyer Monitoring Integration And Batch
Syer Monitoring Integration And Batch
Dave Syer
 
3.java database connectivity
3.java database connectivity3.java database connectivity
3.java database connectivity
web360
 

What's hot (19)

A presentation on WCF & REST
A presentation on WCF & RESTA presentation on WCF & REST
A presentation on WCF & REST
 
Ch06 edge transport
Ch06 edge transportCh06 edge transport
Ch06 edge transport
 
Integration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud FoundryIntegration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud Foundry
 
Ch05 high availability
Ch05 high availabilityCh05 high availability
Ch05 high availability
 
Mule splitters
Mule splittersMule splitters
Mule splitters
 
Splitters in mule
Splitters in muleSplitters in mule
Splitters in mule
 
Networking in java, Advanced programming
Networking in java, Advanced programmingNetworking in java, Advanced programming
Networking in java, Advanced programming
 
PyNet
PyNetPyNet
PyNet
 
Remoting and serialization
Remoting and serializationRemoting and serialization
Remoting and serialization
 
Servlet basics
Servlet basicsServlet basics
Servlet basics
 
Concurrency and parallel in .net
Concurrency and parallel in .netConcurrency and parallel in .net
Concurrency and parallel in .net
 
Basic Networking in Java
Basic Networking in JavaBasic Networking in Java
Basic Networking in Java
 
Websocket
WebsocketWebsocket
Websocket
 
Azure Service Bus Performance Checklist
Azure Service Bus Performance ChecklistAzure Service Bus Performance Checklist
Azure Service Bus Performance Checklist
 
shieh06a
shieh06ashieh06a
shieh06a
 
Mule splitters
Mule splittersMule splitters
Mule splitters
 
Đề thi lý thuyết DWSJ Aptech
Đề thi lý thuyết DWSJ AptechĐề thi lý thuyết DWSJ Aptech
Đề thi lý thuyết DWSJ Aptech
 
Syer Monitoring Integration And Batch
Syer Monitoring Integration And BatchSyer Monitoring Integration And Batch
Syer Monitoring Integration And Batch
 
3.java database connectivity
3.java database connectivity3.java database connectivity
3.java database connectivity
 

Similar to Pinterest like site using REST and Bottle

Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
E-Services TP2 ISI by Ettaieb Abdessattar
E-Services TP2 ISI by Ettaieb AbdessattarE-Services TP2 ISI by Ettaieb Abdessattar
E-Services TP2 ISI by Ettaieb Abdessattar
Abdessattar Ettaieb
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
Techglyphs
 
Web Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfWeb Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdf
Raghunathan52
 
Web Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfWeb Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdf
Raghunathan52
 
IRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce SiteIRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce Site
IRJET Journal
 
Http and REST APIs.
Http and REST APIs.Http and REST APIs.
Http and REST APIs.
Rahul Tanwani
 
Tutorial_Rest_API_For_Beginners_125.pptx
Tutorial_Rest_API_For_Beginners_125.pptxTutorial_Rest_API_For_Beginners_125.pptx
Tutorial_Rest_API_For_Beginners_125.pptx
T.Choithram & Sons Dubai
 
session and cookies.ppt
session and cookies.pptsession and cookies.ppt
session and cookies.ppt
Jayaprasanna4
 
Web2 0 Incredibles
Web2 0 IncrediblesWeb2 0 Incredibles
Web2 0 Incrediblesanjeshdubey
 
Updated SAKET MRINAL Resume
Updated SAKET MRINAL ResumeUpdated SAKET MRINAL Resume
Updated SAKET MRINAL ResumeSaket Mrinal
 
53 hui homework2
53 hui homework253 hui homework2
53 hui homework2
huis89
 
rest-api-basics.pptx
rest-api-basics.pptxrest-api-basics.pptx
rest-api-basics.pptx
FikiRieza2
 
21. Application Development and Administration in DBMS
21. Application Development and Administration in DBMS21. Application Development and Administration in DBMS
21. Application Development and Administration in DBMSkoolkampus
 
Introduction To REST
Introduction To RESTIntroduction To REST
Introduction To REST
rainynovember12
 
DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...
DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...
DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...
Dataconomy Media
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
Tiago Knoch
 
Introduction to the World Wide Web
Introduction to the World Wide WebIntroduction to the World Wide Web
Introduction to the World Wide WebAbdalla Mahmoud
 
WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
Jean Michel
 

Similar to Pinterest like site using REST and Bottle (20)

Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
Restful web services
Restful web servicesRestful web services
Restful web services
 
E-Services TP2 ISI by Ettaieb Abdessattar
E-Services TP2 ISI by Ettaieb AbdessattarE-Services TP2 ISI by Ettaieb Abdessattar
E-Services TP2 ISI by Ettaieb Abdessattar
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
Web Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfWeb Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdf
 
Web Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfWeb Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdf
 
IRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce SiteIRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce Site
 
Http and REST APIs.
Http and REST APIs.Http and REST APIs.
Http and REST APIs.
 
Tutorial_Rest_API_For_Beginners_125.pptx
Tutorial_Rest_API_For_Beginners_125.pptxTutorial_Rest_API_For_Beginners_125.pptx
Tutorial_Rest_API_For_Beginners_125.pptx
 
session and cookies.ppt
session and cookies.pptsession and cookies.ppt
session and cookies.ppt
 
Web2 0 Incredibles
Web2 0 IncrediblesWeb2 0 Incredibles
Web2 0 Incredibles
 
Updated SAKET MRINAL Resume
Updated SAKET MRINAL ResumeUpdated SAKET MRINAL Resume
Updated SAKET MRINAL Resume
 
53 hui homework2
53 hui homework253 hui homework2
53 hui homework2
 
rest-api-basics.pptx
rest-api-basics.pptxrest-api-basics.pptx
rest-api-basics.pptx
 
21. Application Development and Administration in DBMS
21. Application Development and Administration in DBMS21. Application Development and Administration in DBMS
21. Application Development and Administration in DBMS
 
Introduction To REST
Introduction To RESTIntroduction To REST
Introduction To REST
 
DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...
DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...
DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
Introduction to the World Wide Web
Introduction to the World Wide WebIntroduction to the World Wide Web
Introduction to the World Wide Web
 
WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
 

Recently uploaded

Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
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
 
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
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
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
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
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
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
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
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
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
 

Recently uploaded (20)

Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
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
 
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
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
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
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
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
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.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...
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
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)
 

Pinterest like site using REST and Bottle

  • 1. CMPE 275 Project 2 Report RESTful social collaboration through Pinterest re-enactment Team: Bhushan Deo (009269403) Deven Pawar (009275994) Dhruv Gogna (005067284) Gaurav Bhardwaj (009297431) Vinay Bhore (009290931)
  • 2. Introduction The main goal of Project 2 is to explore the design and challenges in developing RESTful web services for a social media service such as Pinterest. Sharing content is an important pattern found in all social media services. Providing robust and well documented web services is very important in such products as there are several external clients which use them to access and manipulate stored user data. In this report, we provide a detailed explanation of our team’s design and implementation. High Level Architecture The team’s configuration consists of the following components: 1. Web Services: We expose our functionality to the client using RESTful web services written in Python using the Bottle micro-framework. 2. Database: CouchDB NoSQL database is used to persist user data. It provides data storage as JSON documents and thus naturally maps to the requirements. Also, when client hits our web service and some data is changed, we can verify changes in the database through the web interface (Futon), that comes with CouchDB. 3. couchdb-python library: This library provides interface to interact with CouchDB from python code. In our experience, this was a very well designed library with advanced features like high-level couchDB document to python object mapping, intuitive interfaces and good documentation. 4. Client: For testing, we are using curl to hit our web services and see the response. Curl provides many advanced options to make testing via HTTP requests easy. The following sections explain the functionalities implemented and the web service and database component in detail. These include comments about what we learnt while working on each component.
  • 3. Functionalities This project also required cross team interaction to come up with a stable specification for the web services. As per the specification agreed to by the class, following functionalities were implemented by our team. Here, we observed how the traditional Create, Read, Update and Delete operations in databases, map exactly to HTTP methods POST, GET, PUT and DELETE respectively. Functionality Endpoint (fields in angular brackets are generated on the server) CRUD? HTTP Met- hod Request Parameters (all are string type unless specified) Sign up http://localhost:8080/users/signUp Create POST firstName lastName emailId password Login http://localhost:8080/users/login/ Create POST emailId password Create a board http://localhost:8080/users/<userId>/boards/ Create POST boardName boardDesc category isPrivate(Boolean) Get all boards http://localhost:8080/users/<userId>/boards/ Read GET None Get details of a single board http://localhost:8080/users/<userId>/boards/<boardId>/ Read GET None Update Board http://localhost:8080/users/<userId>/boards/<boardId>/ Update PUT boardName boardDesc category isPrivate(Boolean) Delete Board http://localhost:8080/users/<userId>/boards/<boardId>/ Delete DELETE None Create Pin http://localhost:8080/users/<userId>/boards/<boardId>/p ins/ Create POST pinName image description Get a single pin from a board http://localhost:8080/users/<userId>/boards/<boardId>/p ins/<pinId>/ Read GET None Get all pins from a board http://localhost:8080/users/<userId>/boards/<boardId>/p ins/ Read GET None Update a pin http://localhost:8080/users/<userId>/boards/<boardId>/p ins/<pinId>/ Update PUT pinName image description Delete a pin http://localhost:8080/users/<userId>/boards/<boardId>/p ins/<pinId>/ Delete DELETE None Add a comment to a pin http://localhost:8080/users/<userId>/boards/<boardId>/p ins/<pinId>/comment/ Create POST description View comments on a pin http://localhost:8080/users/<userId>/boards/<boardId>/p ins/<pinId>/comment/ Read GET None
  • 4. The responses were returned in JSON format and contained relevant data and endpoint information for subsequent operations as agreed to by the class. Web Services Why Web Services fit in this project? Essentially, web services help de-couple the client and the server implementations. User performs various CRUD operations on an external system by sending HTTP requests through the client. The web service layer, intercepts these requests on the server, performs operations on the database and sends back appropriate response to the client. This fits well with the sharing and collaboration required by social media products. From real world examples such as Facebook, Twitter and Pinterest, it can be seen that a robust and well documented RESTful API is a vital contributor to these products going viral. Bottle: Web services were written in Python using the Bottle micro-framework. We found Bottle to be very intuitive for creating our web services. The framework is very lightweight and in order to use it, it only requires us to include one bottle.py file in the project directory. Server: Bottle runs by default on a single threaded WSGI server, but has adapters to various multi-threaded servers such as paste and Cherrypy which give better performance for applications that need to handle large number of concurrent requests. For testing this project, we have used the default server. Mapping requests to appropriate methods: Various endpoints as mentioned in the functionalities section, map easily to corresponding methods which process the requests at those endpoint, simply by placing a @route decorator above that method. Retrieving data from request: In REST, the URL path determines the data that will be accessed or manipulated and the HTTP method determines the operation that will be performed on that data. - To get information about data that will be accessed, we use wildcards in the URL: @route(‘http://localhost:8080/users/<userId>/boards/<boardId>/’,method=’GET’) def getBoard(userId, boardId): # got userId and boardId from the URL, now perform GET(read) on database - To retrieve data from the HTTP request, bottle provides convenient methods in the request object: @route(‘http://localhost:8080/users/<userId>/boards/<boardId>/’,method=’PUT’) def updateBoard(userId, boardId): # got userId and boardId from the URL, now perform PUT(update)on database # with the fields sent in the request by the client boardName = request.forms.get('boardName') boardDesc = request.forms.get('boardDesc') Returning JSON response: JSON was the decided as the format in which response will be sent back to the client. Even in this case, Bottle made it easy to return back response with “application/json” content type. We simply had to
  • 5. return a python dictionary object. Bottle returns the response in JSON and the appropriate field is set in the HTTP header. @route(‘http://localhost:8080/users/<userId>/boards/<boardId>/’,method=’PUT’) def updateBoard(userId, boardId): # perform appropriate operations return dict(status='OK', message='sample message') If other response types such as html or xml are expected by the client, we are aware that we would have to check for the content types which the client accepts from the HTTP request header and accordingly format the response before sending it back (content negotiation). Handling trailing ‘/’ slash: If some clients put a trailing slash at the end of the endpoint URL, then that is treated as a separate route by Bottle and might not map to the appropriate method in our web service code. Given that we would be testing across teams, this was highly probable. To handle this, Bottle documentation suggests to simply map two routes to the same method, one with a trailing slash and one without a slash. @route(‘http://localhost:8080/users/<userId>/boards/<boardId>/’,method=’PUT’) #No trailing slash @route(‘http://localhost:8080/users/<userId>/boards/<boardId>’,method=’PUT’) def updateBoard(userId, boardId): # perform appropriate operations Database In REST web services, we can think of the URL as a path that is traversed to get to the data that is to be accessed or manipulated. Further, the HTTP method that is specified in the HTTP request gives us the operation (create, read, update or delete) that is to be performed on the data. Accordingly the actions that we take in code depend on the combination of the following factors: 1. Response format accepted by the client (json, xml, html, image, etc..) 2. Data that is to be accessed (URL traversal) 3. What kind of operation on the data (HTTP method type) Thus, for every endpoint there are several combinations that need to be handled so that we process the user request appropriately and so that we return desired response back to the user. In this context, it is clear that we have to organize our data based on the endpoints that we expose to the user. We observed that this is a notable difference compared to Project 1, where there was only one endpoint for the client, and the server queue delegated the message to the appropriate resource to handle. In Project 2, there are several endpoints for the client and each endpoint maps to one method on the server side. The flat schema that we have used to store data in CouchDB is as follows. The “_id” is the userId that is generated server side when the user signs up. This is passed around in each URL and is used to identify user in each subsequent request.
  • 6. { "_id": { "firstName": "", "lastName": "", "emailId": "", "password": "", "isLoggedIn": false, "boards": [ { "boardId": "", "boardName": "", "boardDesc": "", "category": "", "isPrivate": "", "pins": [ { "pinId": "", "pinName": "", "image": "", "description": "", "comments": [] } ] } ] } }
  • 7. Drawback: The limitation of this schema is that for any request, we get the entire complex document associated with a userId from the database. Then, in case of long URLs we have to employ multiple nested loops to get to the data that we require. For example, updating information about a pin needs three nested loops through the document that is returned. This is shown in the figure above. This would be problematic if a user had thousands of boards and pins. A solution to this would be to create separate tables (“databases” in CouchDB) for each step in the endpoint URL tree, i.e. separate tables for user, board and comments, each record containing reference to the userId. However, the tradeoff here is that this would require more queries to the database per user request. Note on Aerospike: Initially we decided on using Aerospike as our database. However, its Python client seems to be under development and there was no support for list and map data structures. Further, there was no query support in the Python client, only full table scan was supported. Hence we decided to go with CouchDB. Nonetheless, it was interesting to understand Aerospike’s architecture and concepts such as location awareness of client, peer relationship among nodes, use of binary wire protocol for communication and cross data center replication. Conclusion For our team, following are the major learnings from this project: 1. Programming in Python 2. RESTful web services 3. Database design for RESTful web services 4. Micro-frameworks 5. Comparison of technologies used in Project 1 and 2 6. CouchDB and Aerospike 7. Collaboration in Small and Large Software Development Teams