Web Service Project
Web Service Project
Group members
No. Name ID
app = Flask(__name__)
books_list = [
"id":1,
"author":"Nicolo Machiavelli",
"language":"English",
"title":"The Prince",
},
"id": 2,
"language": "English",
def books():
if request.method == 'GET':
if len(books_list) > 0:
return jsonify(books_list)
else:
if request.method =='POST':
new_author = request.form['author']
new_lang = request.form['language']
new_title = request.form['title']
new_obj = {
'id': iD,
'author': new_author,
'language': new_lang,
'title': new_title
books_list.append(new_obj)
def single_book(id):
if request.method == 'GET':
if book['id'] == id:
return jsonify(book)
pass
if request.method == 'PUT':
if book['id'] == id:
book['author'] = request.form['author']
book['language'] = request.form['language']
book['title'] = request.form['title']
updated_book = {
'id' : id,
'author' : book['author'],
'language' : book['language'],
'title' : book['title']
return jsonify(updated_book)
if request.method == 'DELETE' :
if book['id'] == id :
books_list.pop(index)
return jsonify(books_list)
if __name__== '__main__':
app.run()
2. From available SED tools, select at least 2 tools and explain them in detail(use practical
assumptions).
- 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
"@example.com" 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.