The Launchpad 🚀 – Kickstart Your Studying Journey – Half 1

0
127

[ad_1]

Welcome to the Launchpad, our new weblog sequence! That is your one-stop store for the whole lot it’s worthwhile to get began with a sure expertise or certification path. It’s additionally the proper place to be in the event you simply need to study one thing cool.

As I exploit my time to select up a brand new ability or research for a certification, I noticed that I don’t all the time know the place to start out. I all the time really feel conflicted as a result of I’ve restricted time to review throughout my work week. That mentioned, I made a decision to start out a weblog sequence to share my studying path with you, our studying group, in hopes that I may help you study one thing new, whereas additionally providing you with some path and assets 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 Knowledgeable certification examination matters.

The Route

For those who haven’t finished so but:

“Decoding the New DevNet Knowledgeable Lab Examination”

Watch #CiscoChat on-demand now.

The Studying

Now that now we have an concept of what is going to be coated 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 internet utility framework (endpoints, HTTP request, and response).

Flask internet framework involves thoughts right here. Let’s construct a easy internet 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 knowledge 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

Jsonlibrary used for Json knowledge manipulation
Flaskinternet utility framework
Tinydbprecisely what it reads, a tiny database

2. We’re going to construct a poor man’s IPAM, save IP tackle and its corresponding info (masks, vrf, standing… and many others.) to a database and permit Flask to reveal an API endpoint into the information. To take action, let’s create an occasion of Flask and TinyDB.

app = Flask(__name__)
db = TinyDB ('db/knowledge.json')


3. Subsequent use the route decorator to inform Flask what URL ought to set off our perform.

On this case, we accommodate for 5 completely 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 completely different http strategies, however I wished to exhibit 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 operating on {}".format(request.host_url))

5. The /question route will settle for GET technique. The perform will verify for parameters coming in a part of the request name, on this case the ‘ip’ tackle and can do a lookup for the document within the db. If discovered, it can return it. In any other case, it can 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:
consequence = db.search(Question().ipadd == ip)
if consequence:
return jsonify(consequence)
else:
return jsonify(db.all())

Right here’s what the API name seems to be like with the returned knowledge. It’s all the time excellent news while you see 200 OK:

6. Let’s go over another 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 knowledge into the TinyDB

@app.route('/create', strategies=['POST'])
def create_record():
document = json.masses(request.knowledge)
consequence = 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 to be like:

 

 

 

 

 

 

 

 

 

 

7. Lastly, the essential a part of all of that is to really inform your utility to run the Flask server by defining the Host IP and port. Debug mode is non-obligatory, however beneficial.

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 can assist you focus as you mess around with the code. I may even go away you with some helpful assets to proceed your journey towards turning into a DevNet Knowledgeable:

 

Observe Cisco Studying & Certifications

Twitter, Fb, LinkedIn and Instagram.

 

Share:



[ad_2]