1

When writing services in TypeScript for AngularJS do you define a model for the request and the response?

So for example, given the following service call into a RESTFul endpoint from the service:

module Application {
    export module Services {
        export class MyService {
            public static $inject = ["$http"];

            constructor(private $http: ng.IHttpService) {
            }

            getSomeData = (model: Models.RequestModel): ng.IPromise<Models.ResponseModel> => {
                this.$http.post("url", model).then((response: ng.IHttpPromiseCallbackArg<Models.ResponseModel>) => {
                    return response.data;
                });
            }
        }
    }
}

So basically I am sending the RequestModel and receiving back the ResponseModel

Would that be the proper use/syntax?

1 Answer 1

2

So basically I am sending the RequestModel and receiving back the ResponseModel, Would that be the proper use/syntax?

Yes. Request in, promise to Response out.

Sign up to request clarification or add additional context in comments.

3 Comments

So do I need to use the Models I am using or is that overkill? Does this look like a good solution/pattern? Thanks!!
IMHO using the module keyword is generally an overkill : github.com/TypeStrong/atom-typescript/blob/master/docs/out.md You can put interfaces in a global namespace in a non external module and use external modules everywhere else
Could you provide an example of the above in the way that you feel is the right way to write it? You dont have ti use modules?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.