SlideShare a Scribd company logo
RESTful API
Tamim Shahriar Subeen
Mukto Software Ltd.
In Ancient Days
http://example.com/?command=command_name&param1=p&param2=q...
command = form['command']
if command == 'get_list':
...
elif command == 'create_list':
param1 = form['param1']
param2 = form['param2']
...
elif command == 'update_list':
...
elif command == 'delete_list':
...
else:
print 'Unknown Command'
Framework!
http://example.com/list/?
if request.method == 'GET':
...
if request.method == 'POST':
...
Time passes on ...
HTTP Methods
GET : Read A Resource
POST : Create a Resource
PUT : Update a Resource
DELETE : Delete a Resource
Response
Status Code, Content
Searching ...
Flask-RESTful
class Todo(Resource):
def get(self, todo_id):
abort_if_todo_doesnt_exist(todo_id)
return TODOS[todo_id]
def delete(self, todo_id):
abort_if_todo_doesnt_exist(todo_id)
del TODOS[todo_id]
return '', 204
def put(self, todo_id):
args = parser.parse_args()
task = {'task': args['task']}
TODOS[todo_id] = task
return task, 201
Test Your REST API
Write tests for successful failure!
GET http://example.com/todos/
It should successfully return 404 status code
DELETE http://example.com/todos/-1
It should successfully return 404 status code
Check the status code and also the error message!
Test Your REST API
Write tests for successful success!
GET http://example.com/todos/1
It should successfully return the to_do item with task id 1 and 200 status code
DELETE http://example.com/todos/1
It should successfully delete the task with id 1 return 204 status code
Check the status code first, then validate the response data.
REST API Testing Methods
● Browser Addons
● CURL
● Write Your Own Code
○ requests module
requests.get
requests.put
requests.post
requests.delete
Use a Framework
unittest
Unit testing framework in Python
Code in Action
import requests
import unittest
class TestShopolotApi(unittest.TestCase):
def setUp(self):
print " in setup "
def tearDown(self):
print " in teardown "
def test_login_wrong(self):
print "testing login 1"
url = 'http://example.com/' + 'login'
data = {'email': email, 'password': password_hash}
r = requests.post(url, data)
self.assertEqual(r.status_code, 400)
if __name__ == '__main__':
unittest.main()
Rest API in my experience

More Related Content

PPTX
Secure PHP Coding - Part 2
PPTX
Secure PHP Coding - Part 1
PPT
Mining Ruby Gem vulnerabilities for Fun and No Profit.
PDF
Symfony 2.0 on PHP 5.3
ODP
PDF
Ruby 2.0
PPTX
PHP Basics and Demo HackU
PDF
Building Cloud Castles
Secure PHP Coding - Part 2
Secure PHP Coding - Part 1
Mining Ruby Gem vulnerabilities for Fun and No Profit.
Symfony 2.0 on PHP 5.3
Ruby 2.0
PHP Basics and Demo HackU
Building Cloud Castles

What's hot (6)

PDF
Having Fun Programming!
PDF
Great Developers Steal
PDF
With a Mighty Hammer
PDF
Solr & Lucene at Etsy
PDF
Solr and Lucene at Etsy - By Gregg Donovan
PDF
Building Cloud Castles - LRUG
Having Fun Programming!
Great Developers Steal
With a Mighty Hammer
Solr & Lucene at Etsy
Solr and Lucene at Etsy - By Gregg Donovan
Building Cloud Castles - LRUG
Ad

Similar to Rest API in my experience (20)

PDF
Crafting APIs
PPTX
RESTful Services
PPTX
Building Valuable Restful APIs - HRPHP 2015
ODP
Attacking REST API
PDF
REST API Basics
PDF
REST API Recommendations
PPTX
REST Api Tips and Tricks
PDF
RefCard RESTful API Design
PPTX
Standards of rest api
PPTX
A Deep Dive into RESTful API Design Part 2
PPTX
Rest API Design Rules
PPTX
An Introduction To REST API
PDF
Creating Restful Web Services with restish
PDF
Rest api titouan benoit
PPTX
Pragmatic REST APIs
PPTX
REST with Eve and Python
PDF
Алексей Веркеенко "Symfony2 & REST API"
PDF
Rest in flask
PDF
API Basics
Crafting APIs
RESTful Services
Building Valuable Restful APIs - HRPHP 2015
Attacking REST API
REST API Basics
REST API Recommendations
REST Api Tips and Tricks
RefCard RESTful API Design
Standards of rest api
A Deep Dive into RESTful API Design Part 2
Rest API Design Rules
An Introduction To REST API
Creating Restful Web Services with restish
Rest api titouan benoit
Pragmatic REST APIs
REST with Eve and Python
Алексей Веркеенко "Symfony2 & REST API"
Rest in flask
API Basics
Ad

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Transform Your Business with a Software ERP System
PDF
Nekopoi APK 2025 free lastest update
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
System and Network Administration Chapter 2
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
L1 - Introduction to python Backend.pptx
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
medical staffing services at VALiNTRY
PDF
Digital Strategies for Manufacturing Companies
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Which alternative to Crystal Reports is best for small or large businesses.pdf
Transform Your Business with a Software ERP System
Nekopoi APK 2025 free lastest update
How to Choose the Right IT Partner for Your Business in Malaysia
System and Network Administration Chapter 2
Adobe Illustrator 28.6 Crack My Vision of Vector Design
L1 - Introduction to python Backend.pptx
VVF-Customer-Presentation2025-Ver1.9.pptx
Design an Analysis of Algorithms II-SECS-1021-03
medical staffing services at VALiNTRY
Digital Strategies for Manufacturing Companies
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Operating system designcfffgfgggggggvggggggggg
Understanding Forklifts - TECH EHS Solution
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How Creative Agencies Leverage Project Management Software.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf

Rest API in my experience

  • 1. RESTful API Tamim Shahriar Subeen Mukto Software Ltd.
  • 2. In Ancient Days http://example.com/?command=command_name&param1=p&param2=q... command = form['command'] if command == 'get_list': ... elif command == 'create_list': param1 = form['param1'] param2 = form['param2'] ... elif command == 'update_list': ... elif command == 'delete_list': ... else: print 'Unknown Command'
  • 4. Time passes on ... HTTP Methods GET : Read A Resource POST : Create a Resource PUT : Update a Resource DELETE : Delete a Resource Response Status Code, Content
  • 6. Flask-RESTful class Todo(Resource): def get(self, todo_id): abort_if_todo_doesnt_exist(todo_id) return TODOS[todo_id] def delete(self, todo_id): abort_if_todo_doesnt_exist(todo_id) del TODOS[todo_id] return '', 204 def put(self, todo_id): args = parser.parse_args() task = {'task': args['task']} TODOS[todo_id] = task return task, 201
  • 7. Test Your REST API Write tests for successful failure! GET http://example.com/todos/ It should successfully return 404 status code DELETE http://example.com/todos/-1 It should successfully return 404 status code Check the status code and also the error message!
  • 8. Test Your REST API Write tests for successful success! GET http://example.com/todos/1 It should successfully return the to_do item with task id 1 and 200 status code DELETE http://example.com/todos/1 It should successfully delete the task with id 1 return 204 status code Check the status code first, then validate the response data.
  • 9. REST API Testing Methods ● Browser Addons ● CURL ● Write Your Own Code ○ requests module requests.get requests.put requests.post requests.delete
  • 10. Use a Framework unittest Unit testing framework in Python
  • 11. Code in Action import requests import unittest class TestShopolotApi(unittest.TestCase): def setUp(self): print " in setup " def tearDown(self): print " in teardown " def test_login_wrong(self): print "testing login 1" url = 'http://example.com/' + 'login' data = {'email': email, 'password': password_hash} r = requests.post(url, data) self.assertEqual(r.status_code, 400) if __name__ == '__main__': unittest.main()