I've read multiple SO questions on this error, but none of them seem to be helping me resolve this issue. The Falcon server isn't even printing out the print statements of the on_post method (on_get is working fine for some reason), not sure what's wrong with my on_post method.
I'm calling a post method from my localhost:8000 as such:
#client side
var ax = axios.create({
baseURL: 'http://localhost:5000/api/',
timeout: 2000,
headers: {}
});
ax.post('/contacts', {
firstName: 'Kelly',
lastName: 'Rowland',
zipCode: '88293'
}).then(function(data) {
console.log(data.data);
}).catch(function(err){
console.log('This is the catch statement');
});
This is the Falcon server code
import falcon
from peewee import *
#declare resources and instantiate it
class ContactsResource(object):
def on_get(self, req, res):
res.status = falcon.HTTP_200
res.body = ('This is me, Falcon, serving a resource HEY ALL!')
res.set_header('Access-Control-Allow-Origin', '*')
def on_post(self, req, res):
res.set_header('Access-Control-Allow-Origin', '*')
print('hey everyone')
print(req.context)
res.status = falcon.HTTP_201
res.body = ('posted up')
contacts_resource = ContactsResource()
app = falcon.API()
app.add_route('/api/contacts', contacts_resource)
I imagine that I'm making a small error in my on_post method, but I can't tell what it is. I would've assumed that at least the print statements would work but they are not.
