0% found this document useful (0 votes)
14 views5 pages

Web Service Project

The document outlines a project involving the creation of a basic RESTful API using Flask in Python, which manages a list of books with functionalities for retrieving, adding, updating, and deleting book entries. It also discusses two stream editor tools: Sed, which is used for non-interactive text transformations, and Awk, which is designed for pattern scanning and data extraction. Both tools are highlighted for their utility in text processing and automation tasks.

Uploaded by

Mikias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Web Service Project

The document outlines a project involving the creation of a basic RESTful API using Flask in Python, which manages a list of books with functionalities for retrieving, adding, updating, and deleting book entries. It also discusses two stream editor tools: Sed, which is used for non-interactive text transformations, and Awk, which is designed for pattern scanning and data extraction. Both tools are highlighted for their utility in text processing and automation tasks.

Uploaded by

Mikias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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"

@app.route('/books' ,methods=['GET', 'POST'])

def books():
if request.method == 'GET':

if len(books_list) > 0:

return jsonify(books_list)

else:

'Nothing Found', 404

if request.method =='POST':

new_author = request.form['author']

new_lang = request.form['language']

new_title = request.form['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

@app.route('/book/<int:id>', methods=['GET' , 'PUT' , 'DELETE'])

def single_book(id):

if request.method == 'GET':

for book in books_list:

if book['id'] == id:
return jsonify(book)

pass

if request.method == 'PUT':

for book in books_list:

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' :

for index, book in enumerate(books_list):

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).

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
"@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.

You might also like