The Wayback Machine - https://web.archive.org/web/20201003162230/https://github.com/NREL/api-umbrella/issues/187
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin API: Difference using Array or String variable for Headers #187

Open
jykae opened this issue Oct 30, 2015 · 1 comment
Open

Admin API: Difference using Array or String variable for Headers #187

jykae opened this issue Oct 30, 2015 · 1 comment
Labels

Comments

@jykae
Copy link

@jykae jykae commented Oct 30, 2015

Question regarding Admin API: What is the difference using Array or String variables for Headers? Which one is preferred for passing headers?

"headers": [
        {
          "id": "string",
          "key": "string",
          "value": "string"
        }
      ],
      "headers_string": "string",
      "default_response_headers": [
        {
          "id": "string",
          "key": "string",
          "value": "string"
        }
      ],
      "default_response_headers_string": "string",
      "override_response_headers": [
        {
          "id": "string",
          "key": "string",
          "value": "string"
        }
      ],
      "override_response_headers_string": "string",
@GUI
Copy link
Member

@GUI GUI commented Nov 11, 2015

Ah, good question. The *_string variants are virtual attributes that correspond to the array/object versions (the raw string versions aren't stored in the database anywhere). The *_string variants are really only there to to make it easier to support our default admin UI where we present these headers as a textarea where you can enter a single header per row. Having these duplicative *_string inputs might not be the best from an API or data modeling perspective, but we do have them, and that is what we currently use for our form display and submission. Since the string versions aren't going anywhere in V1 of the API, I'd say you can really use whichever approach seems easier from your perspective. Both should function the same (you just won't want to pass in both the array and the string for a single option), although since we don't actively use the array/object version, definitely let us know if you see any issues with that.

To explain what's happening behind the scenes, if you submit a headers_string with a value of:

X-Foo: bar
X-Foo2: bar2

That will get parsed, a random UUID generated for the IDs, and then everything stored in the database as something like:

"headers": [
  {
    "id": "3b916600-5686-4dda-9ee4-8c6c31b847fd",
    "key": "X-Foo",
    "value": "bar"
  },
  {
    "id": "23f80228-e4df-40f2-9503-c371cb422eed",
    "key": "X-Foo2",
    "value": "bar2"
  }
]

And then for the API output, it will combine those array/objects back into a single string that would be suitable for display if you want to use a single textarea for all the headers.

@GUI GUI added the documentation label Nov 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.