Install flask dependencies
pip install flaskStart Project
py lyftSample.py
The application should start on http://127.0.0.1 at port 5001 or goto http://127.0.0.1:5001/
LIVE API is directly accessible on
https://lyft-app.herokuapp.com/Route at
/testRequest method
POSTheaders
'Content-Type': "application/json"body
{"string_to_cut": "iamyourlyftdriver"}
for enum, i in enumerate(list(data['string_to_cut'])):
if enum%3 == 2:
output += i
return '%s' % output
- A code snippet from file
lyftSample.py
with app.test_client() as lyftCase:
resp = lyftCase.post('/test', json={
'string_to_cut': 'iamyourlyftdriver'
})
if resp.data.decode('utf-8') == '{"return_string":"muydv"}\n':
print('Test Success:', resp.data.decode('utf-8'))
- A test file
testSample.pyto run sample test case
import requests
method = "POST"
url = "http://127.0.0.1:5001/test"
payload = '{\"string_to_cut\":\"iamyourlyftdriver\"}'
headers = {
'Content-Type': 'application/json',
}
res = requests.request(method=method, url=url, data=payload, headers=headers)
print(res.text)
- cURL
curl --location --request POST "https://lyft-app.herokuapp.com/test" --header "Content-Type: application/json" --data "{\"string_to_cut\": \"iamyourlyftdriver\"}"