Web service – project 1
Group members
No. Name ID
1. Mikias Embaye Mde 8562/18
2. Natnael Alemseged Mde 0124/18
3. Lieltdiana Bahabelom Mdr/ 8219/18
1. Creat a basic restful API using a framework like flask python.
from flask import Flask, request, jsonify
app = Flask(__name__)
books_list = [
"id":1,
"author":"Nicolo Machiavelli",
"language":"English",
"title":"The Prince",
},
"author": "Robert Green",
"id": 2,
"language": "English",
"title": "The Laws Of Human Nature"
@[Link]('/books' ,methods=['GET', 'POST'])
def books():
if [Link] == 'GET':
if len(books_list) > 0:
return jsonify(books_list)
else:
'Nothing Found', 404
if [Link] =='POST':
new_author = [Link]['author']
new_lang = [Link]['language']
new_title = [Link]['title']
iD = books_list [-1] ['id']+1
new_obj = {
'id': iD,
'author': new_author,
'language': new_lang,
'title': new_title
books_list.append(new_obj)
return jsonify(books_list) , 201
@[Link]('/book/<int:id>', methods=['GET' , 'PUT' , 'DELETE'])
def single_book(id):
if [Link] == 'GET':
for book in books_list:
if book['id'] == id:
return jsonify(book)
pass
if [Link] == 'PUT':
for book in books_list:
if book['id'] == id:
book['author'] = [Link]['author']
book['language'] = [Link]['language']
book['title'] = [Link]['title']
updated_book = {
'id' : id,
'author' : book['author'],
'language' : book['language'],
'title' : book['title']
return jsonify(updated_book)
if [Link] == 'DELETE' :
for index, book in enumerate(books_list):
if book['id'] == id :
books_list.pop(index)
return jsonify(books_list)
if __name__== '__main__':
[Link]()
2. From available SED tools, select at least 2 tools and explain them in detail(use practical
assumptions).
here are two popular SED (stream editor) tools:
a. Sed (Stream Editor)
- Sed is a powerful text stream editor that can perform basic text transformations on an input stream
(a file or input from a pipeline) and write the results to an output stream. It is particularly useful for
editing files non-interactively.
- Example: If you have a file containing a list of email addresses and you want to add a domain name to
each address, you can use sed to achieve this. For example, you could use a sed command to add
"@[Link]" to the end of each line in the file.
b. Awk
- Awk is a versatile programming language designed for pattern scanning and processing. It is often
used as a data extraction and reporting tool.
- exampe: If you have a log file with various fields separated by commas and you want to extract
specific columns, you can use awk to accomplish this. For instance, you could use an awk command to
extract the second and third columns from each line in the log file.
These tools are widely used for text processing and manipulation in various scripting and automation
tasks.