trailsjs / trails

:evergreen_tree: Modern Web Application Framework for Node.js.
http://trailsjs.io
Other
1.66k stars 70 forks source link

Provide client side library #84

Open gutenye opened 8 years ago

gutenye commented 8 years ago

It'll be great if we can use same model files in both server and client side. There're something in common, e.g. properties, validation, custom methods

Maybe something like js-data? or automatically generated like loopback

aclave1 commented 8 years ago

I have written some code to automate this for a past project and i plan to provide it as a trailpack. The way i did it in the past was, I added DTO classes to my sails.config.routes file, I then required this file into my client app and ran some code to extract the http method and route template, call the api library of my choice, new() the "send" DTO, pass in the parameters, and whatever comes back, new() the "receive" DTO. On the DTO i had validations and such which ran on the client and on the server.

So a sails.config.routes file looked something like this:

{
'get /url/:id',
controller:'...'
send:CreateChatRoom, //js constructor function
receive:ChatRoom//js constructor function
} 
tjwebb commented 8 years ago

@gutenye yea this would be very good. We have some thoughts but would like input from the community. People like you!

I built something similar for Sails:

also cc @yejodido who may have some ideas

aclave1 commented 8 years ago

I'm going to open source the one I wrote and provide a trailpack for y'all.

aclave1 commented 8 years ago

I ended up rewriting my client library implementation from sails. It's a work in progress and hasn't been tested. Read the readme if you like the general idea: https://github.com/aclave1/trailpack-client