This app is JSON api server for the chatbot in android app
I don't know how exactly to copy a django project but just create a new django project and copy paste all the things from this repo to that folder and append these lines to settings.py
import os
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR,'resources/'),
)
Connect your phone and laptop/pc to a common wifi network and then run
$ python manage.py runserver 192.168.43.111:8000
If your wifi broadcast ip is not 192.168.43.111 then check it and change it accordingly.
- React Native / Javascript: Use fetch API to call the local server at
/api
endpoint. For example:
/**
* @description Calls the endpoint and gets the result back
* @param {string} question for the chatbot
*/
const RequestResponse = async( messageFromUser ) => {
try {
fetch('http://192.168.43.111:8000/api/', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
q: messageFromUser,
}),
}).then((response)=> response.json()).then((responseJSON)=>{
console.log(responseJSON.answer)
});
} catch (err) {
console.log(err);
}
}
- Postman: Run the django server
$ python manage.py runserver 127.0.0.1:8000
Create a new request in postman and modify it as follows...
- Edit the header:
- Add json to the body:
- Add a basic test:
- Send the request: