This is a simple example of how to use Django REST and Elasticsearch to search for with a keyword.
Don't forget to create a .env file with the following variables:
# .env
SECRET_KEY=your_secret_keydocker-compose up --buildbefore continue, wait for everything ready (the elasticsearch wake up may tooks a few seconds)
docker-compose exec api python manage.py create_indexesyou will also want to create a user to use the API:
docker-compose exec api python manage.py createsuperuserdocker-compose exec api python manage.py search_hostname <username> <password> <hostname>curl --request POST \
--url http://localhost:8000/api/search/ \
--header 'Authorization: Octoxlabs <base64_token>' \
--header 'Content-Type: application/json' \
--data '{
"query": "Hostname = octoxlabs*"
}'You can directly run the tests after the containers are up (Step 1)
the others steps are not necessary to run the tests. They are already mocked.
docker-compose exec api python manage.py test