I'm using Epilogue to handle POST requests to create new objects in my database. Or at least, I'm trying to. I can't seem to figure out how to POST data to it.
I first assumed that Epilogue would handle JSON. While the request succeeds, all of the fields are null. In cases where there is a not-null restriction, the request fails as if the field wasn't filled in. For example:
POST /accounts HTTP/1.1
Content-Type: application/json
Content-Length: 23
{"name": "Brad's Test"}
The response from Epilogue:
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Content-Length: 112
ETag: W/"70-1ea2c9c3"
Date: Sun, 08 Mar 2015 17:19:10 GMT
Connection: keep-alive
{"message":"notNull Violation: name cannot be null","errors":[{"field":"name","message":"name cannot be null"}]}
This is a simple model with only one field, name
, and it's required.
var Account = sequelize.define('Account', {
name: {
type: DataTypes.STRING,
allowNull: false,
validate: {
notEmpty: true
}
}
});
The unit tests for Epilogue seem to indicate that it supports JSON. Just in case, I tried a URL-encoded form post instead:
POST /accounts HTTP/1.1
Content-Length: 14
Content-Type: application/x-www-form-urlencoded
name=BradsTest
I got the same response back from Epilogue as I did with the JSON POST.
My Question: What is the proper way to POST to Epilogue?
Unfortunately there is no documentation, nor example within its README.
If it's helpful, here's how I'm setting up Epilogue in my application:
var express = require('express');
var orm = require('sequelize-singleton');
var rest = require('epilogue');
var router = express.Router();
rest.initialize({
app: router,
sequelize: orm.sequelize
});
rest.resource({
model: orm.models.Account,
endpoints: ['/', '/:id']
});
module.exports = router;
Outside of this, I have something like:
app.use('/accounts', require('./services/accounts.js'));
Aucun commentaire:
Enregistrer un commentaire