Internet Of Things 101 Intel® Edison
  • Cover
  • Summary
  • About This Traning
    • Objectives
    • Skills
    • Prerequisites
    • Requirements
  • Once Upon A Time ...
  • Internet Of Things
    • Examples
    • Consortiums
    • Resources
      • Architecture
      • Associations
      • Awards
      • Contests
      • Events
      • Investors
      • Job Roles
      • People
      • Programming Languages
      • Projects
      • Standards
      • Tendencies
      • Training
        • Coursera
      • Licensing
      • Sites
    • Key Players
      • Amazon
      • Apple
      • ARM
      • AT&T
      • Atari
      • Axeda
      • Bosch
      • Cisco
      • Dell
      • Eclipse
      • Facebook
      • General Electric
      • Google
      • Hewlett Packard
      • Huawei
      • IBM
      • Intel
        • Tools
      • IoT Ticket
      • Libelium
      • Oracle
      • Others
      • Mediatek
      • Micrium
      • Microchip
      • Microsoft
      • Mozilla
      • NXP
      • NVIDIA
      • Nokia
      • Predixion
      • PTC
      • Qualcomm
      • RedHat
      • Renesas
      • Salesforce
      • Samsung
      • SAP
      • Schneider Electric
      • Telefonica
      • Texas Instruments
      • ThingWorx
      • Verizon
      • Vodafone
      • C2M
  • Architecture
    • Thing
      • Boards
        • Arduino
        • Beagleboard
        • C.H.I.P.
        • Raspberry Pi
        • ESP8266
        • Intel Architecture
          • Development Workstation
      • Boot Loaders
        • Labs
      • Operating Systems
      • Embedded Linux
        • Board Support Package
          • Labs
        • Boot Up
          • Labs
        • Command Line Interface
          • Labs
        • File Systems
          • Labs
        • Text Editors
          • Labs
        • Package Management System
          • Labs
        • Version Control Systems
          • Labs
        • Programming Languages
          • Python
          • PiP Package Management System
          • Labs
        • Libraries
          • Labs
      • Integrated Development Environments
    • Data
      • Sensors
        • Labs
        • Project
      • Actuators
        • Labs
        • Project
      • Local Operations
      • Frameworks
    • Gateways
      • Intel® IoT Gateways
    • Communications
      • Connectivity
        • Labs
      • Protocols
        • RESTful
          • Labs
        • MQTT
          • Labs
          • Project
    • Cloud Computing
      • Application Programming Interface
        • Labs
        • Project
      • Services
        • Labs
      • Platforms
        • Labs
  • Wrap-Up
    • Online Training
    • Challenge
  • SandBox
    • Sandbox-NonIT
    • IoTPy
    • Analytics
    • Security
    • Cloud
Powered by GitBook
On this page
  • RESTful Labs
  • Flask-RESTful
  1. Architecture
  2. Communications
  3. Protocols
  4. RESTful

Labs

PreviousRESTfulNextMQTT

Last updated 7 years ago

RESTful Labs

Flask-RESTful

Flask-RESTful is an extension for Flask that adds support for quickly building REST APIs. It is a lightweight abstraction that works with your existing ORM/libraries. Flask-RESTful encourages best practices with minimal setup. If you are familiar with Flask, Flask-RESTful should be easy to pick up.

It’s time to write your first REST API. This guide assumes you have a working understanding of Flask, and that you have already installed both Flask and Flask-RESTful.

root@board:~# pip install flask-restful
Downloading/unpacking Flask
  Downloading Flask-0.10.1.tar.gz (544kB): 544kB downloaded
Downloading/unpacking flask-restful
  Downloading Flask-RESTful-0.3.5.tar.gz (102kB): 102kB downloaded
Downloading/unpacking aniso8601>=0.82 (from flask-restful)
  Downloading aniso8601-1.1.0.tar.gz (49kB): 49kB downloaded
Downloading/unpacking python-dateutil (from aniso8601>=0.82->flask-restful)
  Downloading python-dateutil-2.5.1.tar.gz (235kB): 235kB downloaded
Installing collected packages: Flask flask-restful, aniso8601, python-dateutil
Successfully installed Flask flask-restful aniso8601 python-dateutil
Cleaning up...
root@board:~#
root@board:~# vi mainflask.py
#!/usr/bin/python

from flask import Flask
from flask_restful import Api, Resource

app = Flask(__name__)
api = Api(app)

class DataSensorRestApi(Resource):
    def get(self):
        data = 'This is data from a sensor'
        return data

api.add_resource(DataSensorRestApi, '/datasensor')

if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=True)
    root@board:~# python mainflask.py
     * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
     * Restarting with stat
     * Debugger is active!
     * Debugger pin code: 331-202-890

Connect to your boardipaddress:5000/datasensor in a web browser...

Once connected your board will display under the terminal:

    127.0.0.1 - - [28/Dec/2015 15:07:38] "GET /datasensor HTTP/1.1" 200 -
    127.0.0.1 - - [28/Dec/2015 15:07:40] "GET /datasensor HTTP/1.1" 200 -

Once connected your browser will display:

"This is data from a sensor"
Flask-RESTful Documentation
Here