trails icon indicating copy to clipboard operation
trails copied to clipboard

Provide client side library

Open gutenye opened this issue 9 years ago • 4 comments

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

gutenye avatar Jan 14 '16 16:01 gutenye

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
} 

aclave1 avatar Jan 15 '16 02:01 aclave1

@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:

  • https://github.com/tjwebb/sails-backbone
  • https://github.com/tjwebb/sails-backbone-client

also cc @yejodido who may have some ideas

tjwebb avatar Jan 15 '16 23:01 tjwebb

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

aclave1 avatar Jan 18 '16 01:01 aclave1

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

aclave1 avatar Jan 18 '16 16:01 aclave1