Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

docs($httpProvider): add documentation #7782

Closed
wants to merge 2 commits into from
Closed

docs($httpProvider): add documentation #7782

wants to merge 2 commits into from

Conversation

corytheboyd
Copy link
Contributor

Add documentation for $httpProvider default values

Closes #6682

* @description
* Use `$httpProvider` to change the default behavior of the `$http` service.
*
* @property {Object} defaults Default attributes for {@link ng.$http $http} service.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put these properties above the actual properties, so that people remember to update them when those properties change =)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@corytheboyd
Copy link
Contributor Author

Perhaps I am missing something, but there doesn't seem to be an elegant way to document nested attributes of an object:

  /**
   * @ngdoc property
   * @name $httpProvider#defaults
   * @description
   * Default attributes for {@link ng.$http $http} service
   * */
  this.defaults = {
    /**
     * @ngdoc property
     * @name $httpProvider#defaults#headers
     * @description
     * Set default headers for all $http requests. Refer to
     * {@link ng.$http#setting-http-headers $http} for documentation about setting
     * default headers.
     * */
    headers: {
      common: {
        'Accept': 'application/json, text/plain, */*'
      },
      post:   copy(CONTENT_TYPE_APPLICATION_JSON),
      put:    copy(CONTENT_TYPE_APPLICATION_JSON),
      patch:  copy(CONTENT_TYPE_APPLICATION_JSON)
    },
  };

$httpProvider#defaults#headers looks pretty wrong, and doesn't work :P Now that I really think about it, there should be setter functions for all of this stuff:

myAwesomeApp.config('$httpProvider', ['$httpProvider', function($httpProvider) {
  $httpProvider.commonHeaders({ 'Accept': '*/*' });
  $httpProvider.postHeaders(...);
  $httpProvider.putHeaders(...);
  $httpProvider.postHeaders(...);
  $httpProvider.patchHeaders(...);

  $httpProvider.xsrfCookieName('XSRF-TOKEN');
  $httpProvider.xsrfHeaderName('X-XSRF-TOKEN');
}]);

That would be much more work though, I say we just stick to getting these docs updated for now :)

@corytheboyd
Copy link
Contributor Author

I suppose the nesting could be done like this: http://usejsdoc.org/tags-property.html

I wanted to put documentation on the properties themselves, though, because that is rad.

@caitp
Copy link
Contributor

caitp commented Jun 11, 2014

We don't use jsdoc, per se, although dgeni implements some of jsdoc's stuff in some fashion or other

@caitp
Copy link
Contributor

caitp commented Jun 11, 2014

Hmm, looks like other cases in the tree use this format though, so it's possible that dgeni doesn't have the power to do something smarter.

@corytheboyd
Copy link
Contributor Author

Maybe we just mimic the docs of a simple provider like $logProvider:

$httpProvider

Use $httpProvider to change the default behavior of the $http service. Refer to the [$http](a fancy URL) service for documentation on overriding the defaults.

Properties

defaults

@corytheboyd
Copy link
Contributor Author

Could always just fall back to good ol' markdown in the description of defaults to describe the different properties of the object.

@caitp
Copy link
Contributor

caitp commented Jun 11, 2014

Yes, that's what I'm saying. But, TIL there's a bug in the rendering of those... /cc @petebacondarwin compare the rendered page to https://github.com/angular/angular.js/blob/master/src/ng/log.js#L50 --- there are a few things missing.

Add documentation for $httpProvider default values

Closes #6682
As suggested, move the documentation for the defaults object.
@corytheboyd
Copy link
Contributor Author

@caitp Moved the defaults documentation block to where it belongs.

@Narretz Narretz added this to the 1.3.0 milestone Jul 2, 2014
petebacondarwin added a commit that referenced this pull request Jul 3, 2014
petebacondarwin added a commit that referenced this pull request Jul 3, 2014
ckknight pushed a commit to ckknight/angular.js that referenced this pull request Jul 16, 2014
Add documentation for $httpProvider default values

Closes angular#7782
ckknight pushed a commit to ckknight/angular.js that referenced this pull request Jul 16, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I can't find documentation for $httpProvider
3 participants