SlideShare a Scribd company logo
RESTful Web APIs
and MongoDB go for a picnic

Nicola Iarocci

@nicolaiarocci
Nicola Iarocci
Eve REST API Framework, Cerberus, Events
Co-founder @ gestionaleamica.com,
Book Author,
MongoDB Master
Nicola Iarocci
TL;DR
Passionate full stack developer
Il Piccolo
Libro di MongoDB
edizione italiana del libro di Karl Seguin
disponibile per il download @ nicolaiarocci.com
gestionaleamica.com
invoicing & accounting
gestionaleamica.com
your typical old school desktop application
RESTful Web API and MongoDB go for a pic nic
gestionaleamica.com
now going web and mobile
gestionaleamica.com
“ we need a remote

API to keep everything in sync ”

-ha
A

ent
mo m
Before
Client

Database

Desktop!
Application

LAN/SQL
Initial draft
Clients

API

Database

RESTful !
Web API

“Cloud”

?

?

iOS
Android
Website
Desktop Client
Constraints
• minimum viable product first
• add features over time
• frequent database schema updates
• avoid downtime as much as possible
So we started
exploring new paths
MongoDB and REST
!

or why we picked MongoDB for our REST API
JSON-style data store
true selling point for me
JSON for transport
all client to API communication is going to be JSON
JSON & RESTful API
GET

Client

Mongo

JSON!

JSON!

accepted media type

(BSON)

maybe we can push directly to client?
JSON & RESTful API
GET

Client

API

JSON!

JSON!

accepted media type

subset of python dict!
(kinda)

almost.

Mongo
JSON!
(BSON)
JSON & RESTful API
POST

Client
JSON!
objects

API
JSON/dict!
maps to python dict!
(validation layer)

Mongo
JSON!
(BSON)

also works when posting (adding) items to the database
Similarity with
RDBMS
made NoSQL easy to grasp (even for a dumbhead like me)
Terminology
RDBMS

Mongo

Database

Database

Table

Collection

Rows(s)

JSON Document

Index

Index

Join

Embedding & Linking
What about Queries?
Queries in MongoDB are represented as JSON-style objects
// select * from things where x=3 and y="foo"
db.things.find({x: 3, y: "foo”});
Filtering and Sorting
let’s simply expose MongoDB syntax
?where={x: 3, y: "foo”}

Client
native!
Mongo!
query syntax

API
(very) thin
parsing!
& validation
layer

Mongo
JSON!
(BSON)
JSON
all along the pipeline
mapping to and from the database feels more natural
ORM
Where we’re going we don’t need ORMs.
Schema-less
dynamic documents allow for painless, progressive evolution
PyMongo
MongoDB drivers are beautiful. Really.
Also in MongoDB
• setup is a breeze
• lightweight
• fast inserts, updates and queries
• excellent documentation
• great support by 10gen
• great community
REST in practice
!

with some MongoDB love
Collections
API entry point + plural nouns
api.example.com/contacts

collection
to a Mongo
Maps
Document
API entry point + plural nouns + ID
api.example.com/contacts/4f46445fc88e201858000000

on ObjectID
o a collecti
Maps t
GET
Retrieving Resoruce Data
Resource GET
/contacts?where={“age”: {“$gt”: 20}}&projection={“lastname”: 1}

def get_collection(collection):!
documents = []!
cursor = db(collection).find(where, projection)!
for document in cursor:!
documents.append(document)!
return documents

find() accepts a python dict
as query expression, and
returns a cursor we can
iterate
Resource GET
/contacts?where={“age”: {“$gt”: 20}}&projection={“lastname”: 1}

def get_collection(collection):!
documents = []!
cursor = db(collection).find(where, projection)!
for document in cursor:!
documents.append(document)!
return documents

find() accepts a python dict
as query expression, and
returns a cursor we can
iterate
Resource GET
/contacts?where={“age”: {“$gt”: 20}}&projection={“lastname”: 1}

def get_collection(collection):!
documents = []!
cursor = db(collection).find(where, projection)!
for document in cursor:!
documents.append(document)!
return documents

find() accepts a python dict
as query expression, and
returns a cursor we can
iterate
JSON Rendering
JSON Rendering

from Mongo
straight
JSON Rendering
PATCH
Editing a Document
PATCHing
def patch_document(collection, original):!
(...)!
# Perform the update!
db(collection).update({"_Id": ObjectId(object_id)}, !
{"$set": updates})!

mongo update() method
commits updates to the
database.
PATCHing
def patch_document(collection, original):!
(...)!
# Perform the update!
db(collection).update({"_Id": ObjectId(object_id)}, !
{"$set": updates})!

udpate() takes the unique Id
of the document to update
PATCHing
def patch_document(collection, original):!
(...)!
# Perform the update!
db(collection).update({"_Id": ObjectId(object_id)}, !
{"$set": updates})!

$set accepts a dict!
with the updates for the db
eg: {“active”: False}.

updates are atomic
POST
Creating Resources
POSTing
Take #1

def post(collection):!
(...)!
for key, item in docs.items():!
response[ID_FIELD] = db(collection).insert(item)

push document and get its
ObjectId back from Mongo.
like other CRUD operations,
inserting is trivial in
mongo.
POSTing
Take #2

Bulk inserts!!
(let’s look at the code)
after a lot of tinkering
we released an ambitious open

source project
Eve
REST API Framework powered by
Flask, MongoDB and good intentions

python-eve.org
Beta 0.2

• 1.000+ stargazers
• 120 forks

• 24 contributors
• 7.935 downloads
Eve Extensions
contributed by the community

• Eve-ElasticSearch
• Eve-SQLAlchemy
• Eve-Docs
• Eve-Mocks
Wanna see it running?
Hopefully it won’t explode right into my face
Initial draft
Clients

API

Database

RESTful !
Web API

“Cloud”

?

?

iOS
Android
Website
Desktop Client
Production
Clients

API

Database

Adam!

MongoDB

iOS
Android
Website
Desktop Client

eve instance
MongoDB Rocks!
your RESTful Web API
Thank you.
nicolaiarocci

More Related Content

What's hot (20)

PDF
Building Beautiful REST APIs in ASP.NET Core
Stormpath
 
PDF
Native Phone Development 101
Sasmito Adibowo
 
PDF
Differential Sync and JSON Patch @ SpringOne2GX 2014
Brian Cavalier
 
PDF
Updates to the java api for json processing for java ee 8
Alex Soto
 
PPTX
Building Beautiful REST APIs in ASP.NET Core
Nate Barbettini
 
PDF
Analyse Yourself
Norberto Leite
 
PPT
External Data Access with jQuery
Doncho Minkov
 
PPTX
MongoDB + Java - Everything you need to know
Norberto Leite
 
PDF
Apache CouchDB talk at Ontario GNU Linux Fest
Myles Braithwaite
 
PPTX
Introduction to MongoDB and Hadoop
Steven Francia
 
PPTX
Introduction to JSON & AJAX
Collaboration Technologies
 
PPTX
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
PPTX
Beautiful REST+JSON APIs with Ion
Stormpath
 
PPT
Understanding REST
Nitin Pande
 
PDF
REST, RESTful API
Hossein Baghayi
 
PDF
Building Your First MongoDB App
Henrik Ingo
 
PDF
Building Apps with MongoDB
Nate Abele
 
ODP
Introducing CouchDB
Hatem Ben Yacoub
 
PDF
Build REST APIs like a Jedi with Symfony2
Almog Baku
 
PDF
Retrofit Android by Chris Ollenburg
Trey Robinson
 
Building Beautiful REST APIs in ASP.NET Core
Stormpath
 
Native Phone Development 101
Sasmito Adibowo
 
Differential Sync and JSON Patch @ SpringOne2GX 2014
Brian Cavalier
 
Updates to the java api for json processing for java ee 8
Alex Soto
 
Building Beautiful REST APIs in ASP.NET Core
Nate Barbettini
 
Analyse Yourself
Norberto Leite
 
External Data Access with jQuery
Doncho Minkov
 
MongoDB + Java - Everything you need to know
Norberto Leite
 
Apache CouchDB talk at Ontario GNU Linux Fest
Myles Braithwaite
 
Introduction to MongoDB and Hadoop
Steven Francia
 
Introduction to JSON & AJAX
Collaboration Technologies
 
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
Beautiful REST+JSON APIs with Ion
Stormpath
 
Understanding REST
Nitin Pande
 
REST, RESTful API
Hossein Baghayi
 
Building Your First MongoDB App
Henrik Ingo
 
Building Apps with MongoDB
Nate Abele
 
Introducing CouchDB
Hatem Ben Yacoub
 
Build REST APIs like a Jedi with Symfony2
Almog Baku
 
Retrofit Android by Chris Ollenburg
Trey Robinson
 

Viewers also liked (20)

PDF
Building RESTful Services With Go and MongoDB
Shiju Varghese
 
PDF
Diabetes and Me: My Journey So Far
Jason Myers
 
KEY
Quattro passi tra le nuvole (e non scordate il paracadute)
Nicola Iarocci
 
KEY
Fuga dalla Comfort Zone
Nicola Iarocci
 
PDF
Filling the flask
Jason Myers
 
PDF
Intro python-object-protocol
Shiyao Ma
 
PPTX
Hands on django part 1
MicroPyramid .
 
PDF
CoderDojo Romagna
Nicola Iarocci
 
PDF
Python Static Analysis Tools
Jason Myers
 
PDF
Introduction to SQLAlchemy and Alembic Migrations
Jason Myers
 
PDF
Online / Offline
Nicola Iarocci
 
PDF
Coderfaire Data Networking for Developers
Jason Myers
 
PPT
Flask - Python microframework
André Mayer
 
PDF
Introduction to SQLAlchemy ORM
Jason Myers
 
PDF
We Are All Remote Workers
Nicola Iarocci
 
PDF
Impact of Restful Web Architecture on Performance and Scalability
Sanchit Gera
 
PDF
Web develop in flask
Jim Yeh
 
PDF
Selenium testing
Jason Myers
 
PDF
Django channels
Andy Dai
 
PDF
Rest api with Python
Santosh Ghimire
 
Building RESTful Services With Go and MongoDB
Shiju Varghese
 
Diabetes and Me: My Journey So Far
Jason Myers
 
Quattro passi tra le nuvole (e non scordate il paracadute)
Nicola Iarocci
 
Fuga dalla Comfort Zone
Nicola Iarocci
 
Filling the flask
Jason Myers
 
Intro python-object-protocol
Shiyao Ma
 
Hands on django part 1
MicroPyramid .
 
CoderDojo Romagna
Nicola Iarocci
 
Python Static Analysis Tools
Jason Myers
 
Introduction to SQLAlchemy and Alembic Migrations
Jason Myers
 
Online / Offline
Nicola Iarocci
 
Coderfaire Data Networking for Developers
Jason Myers
 
Flask - Python microframework
André Mayer
 
Introduction to SQLAlchemy ORM
Jason Myers
 
We Are All Remote Workers
Nicola Iarocci
 
Impact of Restful Web Architecture on Performance and Scalability
Sanchit Gera
 
Web develop in flask
Jim Yeh
 
Selenium testing
Jason Myers
 
Django channels
Andy Dai
 
Rest api with Python
Santosh Ghimire
 
Ad

Similar to RESTful Web API and MongoDB go for a pic nic (20)

PDF
MongoDB: a gentle, friendly overview
Antonio Pintus
 
PPTX
MongoDB + Spring
Norberto Leite
 
PPTX
MongoDB and Spring - Two leaves of a same tree
MongoDB
 
PDF
Building your first app with MongoDB
Norberto Leite
 
PDF
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
Prasoon Kumar
 
PDF
Confluent & MongoDB APAC Lunch & Learn
confluent
 
PPTX
MongoDB Evenings Minneapolis: MongoDB is Cool But When Should I Use It?
MongoDB
 
PDF
MongoDB Atlas Workshop - Singapore
Ashnikbiz
 
PPTX
Introduction to MongoDB
MongoDB
 
KEY
MongoDB, PHP and the cloud - php cloud summit 2011
Steven Francia
 
PPTX
introtomongodb
saikiran
 
PDF
Build your first MongoDB App in Ruby @ StrangeLoop 2013
Steven Francia
 
PDF
MongoDB for Coder Training (Coding Serbia 2013)
Uwe Printz
 
PPTX
How to learn MongoDB for beginner's
surajkumartpoint
 
PPTX
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
PDF
1428393873 mhkx3 ln
WilfredodelaCernaJr
 
PDF
MongoDB NoSQL database a deep dive -MyWhitePaper
Rajesh Kumar
 
PDF
Building Your First MongoDB Application
Tugdual Grall
 
PPTX
Getting Started with MongoDB using Node.js
Nic Raboy
 
PDF
Introduction to MongoDB
Mike Dirolf
 
MongoDB: a gentle, friendly overview
Antonio Pintus
 
MongoDB + Spring
Norberto Leite
 
MongoDB and Spring - Two leaves of a same tree
MongoDB
 
Building your first app with MongoDB
Norberto Leite
 
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
Prasoon Kumar
 
Confluent & MongoDB APAC Lunch & Learn
confluent
 
MongoDB Evenings Minneapolis: MongoDB is Cool But When Should I Use It?
MongoDB
 
MongoDB Atlas Workshop - Singapore
Ashnikbiz
 
Introduction to MongoDB
MongoDB
 
MongoDB, PHP and the cloud - php cloud summit 2011
Steven Francia
 
introtomongodb
saikiran
 
Build your first MongoDB App in Ruby @ StrangeLoop 2013
Steven Francia
 
MongoDB for Coder Training (Coding Serbia 2013)
Uwe Printz
 
How to learn MongoDB for beginner's
surajkumartpoint
 
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
1428393873 mhkx3 ln
WilfredodelaCernaJr
 
MongoDB NoSQL database a deep dive -MyWhitePaper
Rajesh Kumar
 
Building Your First MongoDB Application
Tugdual Grall
 
Getting Started with MongoDB using Node.js
Nic Raboy
 
Introduction to MongoDB
Mike Dirolf
 
Ad

Recently uploaded (20)

PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Digital Circuits, important subject in CS
contactparinay1
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 

RESTful Web API and MongoDB go for a pic nic