Sunday 11 June 2017

Automatic Deserialization in API

In .NET WebAPI, we can get a request in a specific object. For example:

[HttpPost]
public void PostObject([FromBody] MyClass theObject)
{
     // some process on theObject
}

Is there anyway like this in nodejs? Is there any suggestion to do this in "restify"?

I have get the result in restify like the following:

server.post(`path`,(req: restify.Request, res: restify.Response, next: restify.Next) => {
    // do some process here
})

As you see, to finding the request parameters, I should use req.params.objectName.properyName. Therefore the question is how can I access to the object as an object of a known class in nodejs automatically, like WebAPI in C#?



via OmG

No comments:

Post a Comment