Skip to content

Instantly share code, notes, and snippets.

@RobAWilkinson
Last active August 29, 2015 14:21
Show Gist options
  • Save RobAWilkinson/e1c8ae9e185bce3282c6 to your computer and use it in GitHub Desktop.
Save RobAWilkinson/e1c8ae9e185bce3282c6 to your computer and use it in GitHub Desktop.
Rails API creation lab

Api Lab

###Your mission for todo is to create an api that returns sneakers and stores

I have a tool that will check your test coverage I want to see a high percentage This needs to be on github

I'm going to be a client and give you a spec sheet Here is your spec sheet.

This is to show a particular sneaker

// endpoint 
// "/api/v1/sneakers/1"

//response
{
	"id": 1,
	"name": "Airmax",
	"brand": "nike",
	"cost": 100,
	"color": "white",
}

This is to show an array of sneakers

// endpoint
// "/api/v1/sneakers"

// response
[
	{
		"id": 1,
		"name": "Airmax"
	},
	{
		"id": 2,
		"name": "Samba"
	}
	// and so on
]

You can do a search to find a sneaker by any param

here we do a search by name

//endpoint
// "api/v1/search?name=samba

// response
[
	{
		"id": 2,
		"name": "Samba",
		"brand": "Adidas",
		"color": "black"
	},
	{
		"id": 32,
		"name": "Samba",
		"brand": "Adidas",
		"color": "red"
	}
]

you should also be able to do a search by brand. (the search should be case-insensitive btw)

// endpoint
// 'api/v1/search?brand=adidas'

// response
[
	{
		"id": 2,
		"name": "Samba",
		"brand": "Adidas",
		"color": "black"
	},
	{
		"id": 32,
		"name": "Samba",
		"brand": "Adidas",
		"color": "red"
	}
]

You should be able to look up stores to and find all the different shoes that they have in stock

// endpoint
// 'api/v1/stores/2

// response
{
	"id": 2,
	"name": "Stanley's Shoe Shack",
	"address": "73 and the jamboree",
	"city" "Newport Beach",
	"state": "CA",
	"zipcode": "90031"
	"inventory": [
		{ "id": 32, "cost": 45, "quantity": 0 },
		{ "id": 4, "cost": 150, "quantity": 3 }
	]
}

And get a listing of all the stores

// endpoint
// 'api/v1/stores'

// response

[
	{
		"id": 2,
		"name": "Stanley's Shoe Shack"
	},
	{
		"id": 1,
		"name": "Rob's boot barn"
	}
]

As a bonus challenge it should be able to look up and only load stores on a radius, you can set this radius or the default is 100 miles

// endpoint
// api/v1/stores?zip=90041&radius=20

// response
	[
		{ 
			"id": 11,
			"name": "Eagle rock sandals"
		},
		{
			"id": 5,
			"name": "Silverlake Sneaker Store"
		}
	]
	
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment