Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi I have this code and I need help figuring out how to add http://localhost/hello?name=world and HTTP POST the JSON data:{string1:hello,string2:world} to http://localhost?strings. The first

Hi I have this code and I need help figuring out how to add http://localhost/hello?name="world" and HTTP POST the JSON data:{string1:"hello",string2:"world"} to http://localhost?strings. The first part I believe I already have finished, but if you could look over this to see what I else I need to add

#!/usr/bin/python

import json

from bson import json_util

import bottle

from bottle import route, run, request, abort

id = 0

set up URI paths for REST service

@route('/currentTime',method='GET')

def get_currentTime():

global id

id = id + 1

try:

request.query.name

name = request.query.name

dateString=datetime.datetime.now().strftime("%Y-%m-%d")

timeString=datetime.datetime.now().strftime("%H:%M:%S")

string="{\"date\":"+dateString+",\"time\":"+timeString+"}"

return json.loads(json.dumps(string,indent=4, default=json_util.default))

if__name__=='__main__': declare instance of request

#app.run(debug=True)

run(host='localhost',port=8080)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions