This is a demo project that displays customized hello world message
When a user with the specified name is found, an update will be performed. If the update operation is successful, an empty response with status code
201
will be returned.When a user with the specified name is not found, an instance / record will be created. An empty response with status code
201
will be returned.
When a user's birthday is today, the message returned will be Hello {name}! Happy birthday
When a user's birthday is 5 days away, the message returned will be Hello {name}! Your birthday is in 5 days
Otherwise, the message returned will be Hello {name}!
To activate a virtual environment in Linux
python -m venv {project_name} cd {project_name} source bin/activate
To activate a virtual environment in Mac
virtualenv {project_name} cd {project_name} source bin/activate
pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
gunicorn -b 0.0.0.0:{port} hello_world.wsgi:application
echo "127.0.0.1 mylab.test"
(Note that the Django application has been configured to allow only mylab.test. To change this, edit the line in hello_world/settings.py containing the following
ALLOWED_HOSTS = ['mylab.test'])
8000
is where the Django application is configured to listen on.
Birthday is before current
$ curl mylab.test:8000/hello/john/ -XPUT -d '{"name": "john", "dob": "2001-01-01"}' 201 $ curl mylab.test:8000/hello/john/ {"data":"Hello john!"}
Birthday is after current
$ curl mylab.test:8000/hello/john/ -XPUT -d '{"name": "john", "dob": "2001-11-11"}' 201 $ curl mylab.test:8000/hello/john/ {"data":"Hello john!"}
Birthday is 5 days away
$ curl mylab.test:8000/hello/john/ -XPUT -d '{"name": "john", "dob": "2001-05-11"}' 201 $ curl mylab.test:8000/hello/john/ {"data":"Hello john! Your birthday is in 5 days”}
Birthday is today
$ curl mylab.test:8000/hello/john/ -XPUT -d '{"name": "john", "dob": "2001-05-06"}' 201 $ curl mylab.test:8000/hello/john/ {"data":"Happy birthday, john!"}