简体   繁体   中英

Using an API key in Rails App

I just got an API key for a database I wish to access and want to start building my Rails app. However I dont know where to begin with the API key. Specifically I want to use the brewerydb data and I am building an app where users can find the closest brewery to their location. Can anyone tell me how to get started? I am new to Rails and have never used an API before. I don't know where to begin. What file should I put it in, etc... I know I should probably update the GEMFILE, where else?

Thanks!

Check the documentation for the API. That's all I can say. (well... not really: )

Most API's rely on REST or SOAP, which is basically making HTTP request to certain URI's. An example may be

http://api.somewebsite.com/beers.json

Which would return, for instance, a JSON array of certain beers and their properties.

Furthermore, more often than not, you can test API's (that do not require certain HTTP headers for authentication, which makes it harder) by manually constructing the URI's and opening them in your browser. This way, you can verify that your request is okay before you try it in your Rails application an cannot figure out why it's not working.

You should use the 'figaro' gem https://github.com/laserlemon/figaro

It creates a "application.yml" file in which you can add your API key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM