Skip to content

Conversation

@mikenz1000
Copy link

I'm about to release a package that lets you generate Knockout viewmodels automatically against the meanify SCRUD endpoints. Something missing was a way to get a blank model object for the purpose of binding against a form used for the CREATE operation.

This PROPFIND endpoint returns an object that has null for all fields in the model, except for any that have default values. Default values that are functions will be evaluated each time.

e.g. PROPFIND /api/posts
returns { title:null,author:null ... }

PROPFIND is an 'extension method' under the http spec (https://tools.ietf.org/html/rfc2616) and is one of the routing methods supported by express (http://expressjs.com/guide/routing.html). Happy to change to a different endpoint if you think it makes more sense (e.g. GET /api/posts/__blank or something?)

@artzstudio
Copy link
Collaborator

Thanks for submitting this pull request, it's a really interesting idea and I like that you can get a fresh object without actually creating the resource.

I hesitate to accept the request, since PROPFIND as specified in RFC 2518 is used for retrieving specific property values on a resource.

Here is a stack overflow asking for advice on what you are trying to do.

One answer suggests adding a /template endpoint (i.e. /users/template), while another suggests a POST to /users and getting back the newly created object. I'm partial to the second approach.

Perhaps we could accept a POST to /users without a body, detect there were no properties submitted, and return the empty object? Up for suggestions.

@mikenz1000
Copy link
Author

Ah! Thanks for the stack overflow reference- just what I needed. Will
digest that and make another proposal. Cheers, Mike

On Tuesday, 13 October 2015, Dave Artz [email protected] wrote:

Thanks for submitting this pull request, it's a really interesting idea
and I like that you can get a fresh object without actually creating the
resource.

I hesitate to accept the request, since PROPFIND as specified in RFC 2518
https://tools.ietf.org/html/rfc2518#section-8.1 is used for retrieving
specific property values on a resource.

Here is a stack overflow
http://stackoverflow.com/questions/4932315/restful-design-return-an-empty-object-as-a-template-for-create-new-form
asking for advice on what you are trying to do.

One answer suggests adding a /template endpoint (i.e. /users/template),
while another suggests a POST to /users and getting back the newly created
object. I'm partial to the second approach.

Perhaps we could accept a POST to /users without a body, detect there were
no properties submitted, and return the empty object? Up for suggestions.


Reply to this email directly or view it on GitHub
#3 (comment).

@mikenz1000
Copy link
Author

Ok - done.

By the way when I did a fresh clone to test it I encountered issues with the version of mongoose being referenced (^3.8.19): Got a big "This is an UNSTABLE release of Mongoose." warning and then an exception in the mongoose code: "TypeError: Cannot read property 'length' of undefined". I fixed it by changing the package.json devDependency to "mongoose": "^4.1.11"

This is a separate issue from the pull request though, so didn't include it.

@mikenz1000 mikenz1000 changed the title Added PROPFIND endpoint to pull a blank object for binding to forms for CREATE operations Added blank POST endpoint to pull a blank object for binding to forms for CREATE operations Oct 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants