An API built on Flask-RESTful that returns with the names of all the states in USA.
A REST API to return names of the states of U.S.A. This API is built on Flask-restful.
Follow the steps below to create a REST app on your Linux machine.
Make sure you have installed python-pip First create a virtial environment using pip.
$ sudo apt-get install python-virtualenv
Create an evironment of your own. Use a separate folder where you want to have the virtual setup. Here I’m creating a folder _statesofusa_env_ then a _venv_ within.
$ mkdir statesofusa_env $ cd statesofusa_env $ virtualenv venv
New python executable in venv/bin/python Installing distribute…………done.
Now enter the virtual environment
$ . venv/bin/activate
Once this is done, you will be inside the virtual mode. (notice the prompt shows a venv environment) Now install Flask and Flask-restful
$ pip install Flask $ pip install flask-restful
Once you have done that. All your requirements are ready. You now have to get the [StatesofUSA](https://github.com/ishammi/StatesofUSA/) git repository.
$ git clone email@example.com:<your_git_username>/StatesofUSA.git
Now to run RESTapi server. Run the _main.py_ file
$ cd statesofusa/ $ python main.py * Running on http://127.0.0.1:5000/ * Restarting with reloader
Congratulations.. Your Flask REST server is up and running in the local machine on port 5000. However the API is routed to the URL http://127.0.0.1:5000/states/ For convinience, we have hard coded few authorization parameters. Use the token ‘38c50d14-436b-4e3e-b447-e2e9334fea1a’ to hit the API from outside the virtual environment. Here’s an example
$ curl -H “Authorization: token 38c50d14-436b-4e3e-b447-e2e9334fea1a” –data “page=1&items_per_page=10” http://127.0.0.1:5000/states/
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size StatesofUSA-0.1-py2.7.egg (14.5 kB)||File type Egg||Python version 2.7||Upload date||Hashes View|