pksunkara / alpaca

Given a web API, Generate client libraries in node, php, python, ruby
Mozilla Public License 2.0
2.45k stars 89 forks source link

Default headers for clients #32

Open marfarma opened 10 years ago

marfarma commented 10 years ago

My API requires custom headers, for a use case similar to this scenario:

Where I've seen custom headers com up is in a system to system request operating on behalf of a user. The proxy system will validate the user and add "X-User: userid" to the headers and use the system credentials to hit the endpoint. The receiving system validates that the system credentials are authorized to act on behalf of the user, then validate that the user is authorized to perform the action. http://stackoverflow.com/a/9169270/149060

I was concerned that I didn't see support for them in the todo list.

pksunkara commented 10 years ago

How do you think the client library should behave in this?

You can send headers when making an API call using the client. Wouldn't that solve this issue?

pksunkara commented 10 years ago

@marfarma Could you describe this case more? Do you want the api clients to have some default headers?

marfarma commented 10 years ago

Yes, exactly that. In my case the API is to a service that implements a facade against another API. Attributes required to connect to that API must exist in each request against mine. Rather than pollute every request payload, I expect a header with those values.

My thoughts were that I should be able to define required connection constants, and associated header formatting, encoding, etc. The values would be assigned once per connection instance of the client library. The library then builds the required headers and inserts them on each request.