[ad_1]
Welcome to the Launchpad, our new weblog sequence! That is your one-stop store for the whole lot it’s essential get began with a sure know-how or certification path. Itβs additionally the right place to be when you simply wish to be taught one thing cool.
As I exploit my time to choose up a brand new ability or research for a certification, I spotted that I donβt all the time know the place to begin. I all the time really feel conflicted as a result of I’ve restricted time to review throughout my work week. That stated, I made a decision to begin a weblog sequence to share my studying path with you, our studying group, in hopes that I will help you be taught one thing new, whereas additionally providing you with some course and sources to get you over the end line! All whereas making it enjoyable!
The following couple of Launchpad weblog sequence will give attention to the Cisco Licensed DevNet Professional certification examination matters.
The Course
When you havenβt executed so but:
βDecoding the New DevNet Professional Lab Examinationβ
Watch #CiscoChat on-demand now.
The Studying
Now that we have now an concept of what’s going to be lined within the certification examination, letβs begin with essentially the most closely weighted matter.
Coming in at 30 %: Infrastructure as Code.
- Construct, handle, and function a Python-based REST API with an online utility framework (endpoints, HTTP request, and response).
Flask net framework involves thoughts right here. Letβs construct a easy net utility collectively.
The applying
- Written in python leveraging Flask framework
- Will obtain HTTP requests by way of Postman
- Deal with GET/POST/PUT/DELETE strategies
- Return information based mostly on API requests to endpoints
Easy sufficient, proper? Letβs get began:
1. First, as with something Python, letβs import the required libraries.
import json from flask import Flask, request, jsonify from tinyDB import TinyDB, Question, the place import random
Json β library used for Json information manipulation
Flask β net utility framework
Tinydb β precisely what it reads, a tiny database
2. We’re going to construct a poor manβs IPAM, save IP deal with and its corresponding data (masks, vrf, standingβ¦ and so forth.) to a database and permit Flask to reveal an API endpoint into the info. To take action, letβs create an occasion of Flask and TinyDB.
app = Flask(__name__)
db = TinyDB ('db/information.json')
3. Subsequent use the route decorator to inform Flask what URL ought to set off our operate.
On this case, we accommodate for 5 totally different URLs:
- / β Default route
- /question GET β to retrieve data
- /create POST β to insert data
- /replace PUT to β replace present data
- /delete DELETE β to take away a document
I might have used the default route with 4 totally different http strategies, however I wished to reveal routes. Β―_(γ)_/Β―
4. Default route, the return msg, will show in your browser when you navigate to the serverβs URL.
@app.route('/') def index(): return ("Welcome to Launchpad π - Flask APP is up and working on {}".format(request.host_url))
5. The /question route will settle for GET technique. The operate will examine for parameters coming in a part of the request name, on this case the βipβ deal with and can do a lookup for the document within the db. If discovered, it would return it. In any other case, it would return all data. I leveraged TinyDBβs Question() technique to look.
@app.route('/question', strategies=['GET']) def query_records(): ip = request.args.get('ip') for merchandise in db: end result = db.search(Question().ipadd == ip) if end result: return jsonify(end result) else: return jsonify(db.all())
Right hereβs what the API name seems like with the returned information. Itβs all the time excellent news once you see 200 OK:
6. Letβs go over yet one more route collectively earlier than I ship you over to have a peek on the accomplished code.
/create route is used to insert a brand new document in your makeshift IPAM utility. It accepts POST technique, captures the request physique and inserts information into the TinyDB
@app.route('/create', strategies=['POST']) def create_record(): document = json.hundreds(request.information) end result = db.insert({"id": random.randint(1,500), "ipadd": document['ipadd'], "masks": document['mask'], "vrf": document['vrf'], "standing": document['status']}) return jsonify(db.all())
Right hereβs what the API name seems like:
Β
Β
Β
Β
Β
Β
Β
Β
Β
Β
7. Lastly, the necessary a part of all of that is to truly inform your utility to run the Flask server by defining the Host IP and port. Debug mode is optionally available, however really helpful.
if __name__ == '__main__': app.run(host='0.0.0.0', port=105, debug=True)
The Assets
Hey, look! You made it during! And for that, I reward you with this Spotify playlist that will help you focus as you mess around with the code. I will even go away you with some helpful sources to proceed your journey towards turning into a DevNet Professional:
Β
Observe Cisco Studying & Certifications
Twitter, Fb, LinkedIn and Instagram.
Β
Share:
[ad_2]



