Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Flask and AT API's

Avatar for Ian Juma Ian Juma
October 15, 2016

Intro to Flask and AT API's

Flask introduction; AfricasTalking API's introduction

Avatar for Ian Juma

Ian Juma

October 15, 2016
Tweet

More Decks by Ian Juma

Other Decks in Programming

Transcript

  1. API

  2. Flask API from flask import Flask app = Flask(__name__) @app.route("/api")

    def resource(): # perform task return "resource" if __name__ == "__main__": app.run()
  3. API methods from flask import Flask app = Flask(__name__) @app.route("/api”,

    methods=[’POST’, ‘GET’, ‘DELETE’, ‘PUT’]) def resource(): # perform task return "resource" if __name__ == "__main__": app.run()
  4. methods... GET - fetch a resource POST - add a

    resource DELETE - remove a resource PUT - update a resource HEAD - fetch information about a resource without fetching the resource (options)
  5. Library text API from flask import Flask app = Flask(__name__)

    @app.route("/library/api") def resource(): # fetch text from harry potter return harry_potter if __name__ == "__main__": app.run()
  6. Send SMS from AfricasTalkingGateway import AfricasTalkingGateway # gateway instance gateway

    = AfricasTalkingGateway(username, apikey) # send message gateway.sendMessage("+254 703567XXX", "hello...")
  7. Send Airtime from AfricasTalkingGateway import AfricasTalkingGateway # gateway instance gateway

    = AfricasTalkingGateway(username, apikey) # send message gateway.sendAirtime("+254 703567XXX", "amount")
  8. Handling a call from flask import Flask app = Flask(__name__)

    @app.route("/voice/api") def voice(): res = '<Response><Say>"hi, I am testing"</Say></Response>' return res if __name__ == "__main__": app.run()