سؤال

I have decided to use gem HTTParty to implement my Web API in rails. I found a great article, Personal Weather API, that explained thing very well.

For my own purposes though I have created 2 Rails Applications on my own server and I want to use one of them to GET/POST data from the second application.

Can I do this without an API KEY for the sake of getting it up and running? Any examples out there to get this setup for development purposes?

هل كانت مفيدة؟

المحلول

You can always define your API key requirements in an environment file. This way you could define different keys for different environments and postpone any production-related decisions for a later stage.

For example in your development.rb you could have something like this:

config.my_api_key = "TESTING"

which would allow you to use an easy to remember value for your testing purposes.

When you test for the key validity you compare of course against the environment-specific key as in:

if params[:api_key] == Rails.configuration.my_api_key
  # ...

You can have different keys for testing, development, staging, and so on.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top