Skip to content
Cameron Marlow edited this page Feb 12, 2015 · 13 revisions

The data model is specified in urlz.model and the API methods are specified in urlz.sites.api.

The package used, Flask-Restless handles translating the model into an API. Here are a few queries to show how to use the API.

Create a user

HOST=urler.herokuapp.com
curl \
  -X POST \
  -H "Content-type: application/json" \
  -d '{"username": "meandmybadself","name": "Jeffery","email": "meandmybadself@gmail.com","password": "yoyoyoyo"}' \
  https://$HOST/api/user

Authenticate

After you get the auth token, you'll need to send it up as the header Authentication-Token as seen in the next few examples.

curl \
  -X POST \
  -H "Content-type: application/json" \
  -d '{"username":"meandmybadself","password":"yoyoyoyo"}' \
  https://$HOST/api/login

AUTH_TOKEN={response}

Get a specific user

curl \
  -H "Content-type: application/json" \
  -H "Authentication-Token: $AUTH_TOKEN" \
  https://$HOST/api/user/meandmybadself

Add a tag to a user

curl \
  -X PATCH \
  -H "Content-type: application/json" \
  -H "Authentication-Token: $AUTH_TOKEN" \
  -d '{"tags": {"add": {"name": "stuff", "type": "user", "description": "Love this stuff"}}}' \
  https://$HOST/api/user/meandmybadself

Add a URL

If you try to post the URL and it is already there, you'll get the message "IntegrityError". I will work on making this clearer.

curl \
  -X POST \
  -H "Content-type: application/json" \
  -H "Authentication-Token: $AUTH_TOKEN" \
  -d '{"url": "http://boingboing.net/2015/01/20/why-animals-eat-psychoactive-p.html"}' \
  https://$HOST/api/url

Search for a URL

curl \
  -G \
  -H "Content-type: application/json" \
  -H "Authentication-Token: $AUTH_TOKEN" \
  -d 'q={"filters":[{"name":"url","op":"eq","val":"http://boingboing.net/2015/01/20/why-animals-eat-psychoactive-p.html"}]}' \
  https://$HOST/api/url

Add a Post

curl \
  -X POST \
  -H "Content-type: application/json" \
  -H "Authentication-Token: $AUTH_TOKEN" \
  -d '{"canonical_url": "dbd82a53-556b-4f12-a8b3-2ba25ddaed8f","note": "So much style","tags": [{"id": "943f5608-f23d-4c79-9359-8b28872247ca"}]}' \
  https://$HOST/api/post

Clone this wiki locally