Skip to content

feat(http): accept string for method in RequestOptions class and interface #2840

Closed

Description

@jeffbcross

Currently, the method must be of the ResponseMethods TypeScript enum, which is really an integer. So to create a request in TypeScript, one would use the enum to describe the method instead of passing in the method string:

var options = new RequestOptions({
  url: '/foo.json',
  method: RequestMethods.POST
});
var request = new Request(options);

This adds some convenience for TypeScript and Dart users to get some IDE/compiler help to make sure the method is a valid value. But plain old ES5 users probably don't want to pass 0 as the method value. Instead, RequestOptions should have the method property be a union type of RequestMethods | string, and should validate the provided string & throw if not a recognized method.

I'm not sure Request class needs to accept method as a string though. Ideally, we could reduce instances of type ambiguity to public APIs.

Activity

  1. added
    featureLabel used to distinguish feature request from other issues
    on Jul 2, 2015
  2. mgechev commented on Sep 21, 2015

    @mgechev
    Member

    Since Request is exposed by the public API, it may create confusion if the users can pass both strings and RequestMethods to the http methods when using object literals and only RequestMethods when using Request.

    @jeffbcross I added support of passing HTTP method names as strings to RequestOptions here. Do you think it looks okay and ready for PR?

  3. jeffbcross commented on Sep 23, 2015

    @jeffbcross
    ContributorAuthor

    @mgechev I left a couple of comments on the commit, but yeah, looks good! Please PR! I will assign this to myself just to show that someone's working on it (github issues can only be assigned to those with commit access).

  4. self-assigned this
    on Sep 23, 2015
  5. modified the milestone: alpha-38 on Sep 23, 2015
  6. jeffbcross commented on Sep 23, 2015

    @jeffbcross
    ContributorAuthor

    Since Request is exposed by the public API, it may create confusion if the users can pass both strings and RequestMethods to the http methods when using object literals and only RequestMethods when using Request.

    I agree, please also add the normalizeMethod to Request. Request actually is a useful public API, especially in tests.

  7. mgechev commented on Sep 23, 2015

    @mgechev
    Member

    I took another look at Request. It accepts RequestOptions, however, inside the RequestOptions's constructor we already normalize the method name. Which means the following is valid:

    http.request(new Request(new RequestOptions({url: 'https://google.com', method: 'post' })));
    

    However, in case the Request constructor function is used with ES5 it won't work. I added one extra call of normalizeMethodName inside Request's constructor.

    Here is the PR.

  8. jeffbcross commented on Sep 23, 2015

    @jeffbcross
    ContributorAuthor

    @mgechev eventually Request should accept RequestOptionsArgs interface, but that's not in scope for this PR. I think I removed that when I was making Http work for dart some time ago.

  9. mgechev commented on Sep 24, 2015

    @mgechev
    Member

    @jeffbcross I updated the PR. If declaring that the argument of the constructor of Request should be of type RequestOptionsArgs is out of the scope of this PR I can open another one?

  10. jeffbcross commented on Oct 8, 2015

    @jeffbcross
    ContributorAuthor

    Closed via 34518f0

  11. angular-automatic-lock-bot commented on Sep 7, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  12. locked and limited conversation to collaborators on Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

effort1: hoursfeatureLabel used to distinguish feature request from other issues

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions