On Github Vatyx / HackathonPresentation
Created by Sahil Dhanju
Less is More
Show what makes your idea cool!
A set of programming instructions and standards for accessing a Web-based software application.
Essentially it's a way to send or recieve data from a service.
req = requests.post("https://accounts.spotify.com/api/token", data={'grant_type': 'authorization_code', 'code': code, 'redirect_uri': 'http://localhost:8080/woo', 'client_id': '9344d5a91349489488cc51637d912e21', 'client_secret': '5cb043cf9fc546bebc91978ec8a95bc6'}) res = req.json() access_token = res['access_token'] print("This is the access_token: " + access_token);
query = request.args.get('trackname') payload = {'Authorization': 'Bearer ' + access_token} req = requests.get("https://api.spotify.com/v1/search?q=" + query + "&type=track", headers=payload) global currentList currentList = req.json() print("This is the list of tracks: " + currentList)
query == thing['id'] req = requests.get("https://api.spotify.com/v1/tracks/" + query) reqJson = req.json() print("This is the 30 second preview: " + reqJson['preview_url'])
One more note: HTTP verbs are also used to let your front-end client communicate with your backend server.
@app.route('/testendpoint', methods=['GET']) def testendpoint(): payload = {'phrase': 'Hello World'} return jsonify(payload)
function testTheEndpoint() { $.get('/testendpoint', function(data) { var phrase = data.phrase; console.log(phrase); }); }
I chose to use Node.js for the back-end and raw HTML/CSS/Javascript for the front-end
<div class="title">Quick Compliments!</div> <div class="compliment"><span id="quote">Compliment goes here</span></div> <div class="container" onclick="changeQuote()"><span>Get a compliment!</span></div>
html, body { font-family: 'Open Sans'; height: 100%; margin: 0; position: relative; background-color: #3498db; } .container:hover { background-color:#bbb; cursor:pointer; border-radius:30px; } .container { position: absolute; background-color: white; border-radius: 30px; box-shadow: 0px 3px 40px rgba(0, 0, 0, 0.2); max-width: 400px; text-align: center; height: 125px; font-size: 30px; line-height: 125px; font-weight: 100; color: #444; margin: 50px auto; bottom: 0; left: 0; right: 0; } span { display: inline-block; vertical-align: middle; line-height: normal; } .title { font-size: 80px; line-height: 1.5; font-weight: 100; text-align: center; margin: auto; padding: 50px 0; color: white; } .compliment { margin: auto; max-width: 800px; height: 300px; font-size: 50px; line-height: 200px; font-weight: 100; text-center: center; color: #444; text-align: center; color: white; } .button { bottom: 0; width 100px; height: 50px; }
function changeQuote() { $.get('/getcompliment', {name: $("#quote").text()}, function(data) { obj = JSON.parse(data); console.log(obj.stuff); $("#quote").text(obj.stuff); }); }
app.get('/', function (req, res) { res.sendfile('index.html'); }); app.set('port', (process.env.PORT || 5000)); app.listen(app.get('port'), function() { console.log('Node app is running on port', app.get('port')); });
var compliments = ["Dude you rock!", "You look pretty good today.", "You don't look half bad!", "On a scale of 1-10 for personality, you are a solid 9.5.", "You are so cool bro!", "Your hair is on point today.", "How are you so polite?", "I like your jacket.", "Let's hang out and never stop hanging out.", "Teach me how to be as charming as you are!", "Your name is so fun to say", "Your feet are too perfect it's almost illegal.", "Can I have your socks? They look so hot on you", "You're a great gift giver.", "You're my poster child.", "Has anyone told you how perfect your right hand is?", "You are quite strapping M'Lady.", "Your IQ makes ints overflow.", "All my friends know how cool you are!", "Looking fly today I see.", "Wow fishing for compliments again?"];
app.get('/getcompliment', function (req, res) { var obj = JSON.parse(JSON.stringify(req.query)); var temp = ""; while(true) { temp = compliments[Math.floor(Math.random() * (compliments.length))] if (obj.name !== temp) { break; } } res.send('{"stuff": "' + temp +'"}'); });