Guest User

RGAPI_getSummonerById

a guest
Sep 12th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. const https = require('https');
  4.  
  5. exports.handler = (event, context, callback) => {    
  6.     // API Key
  7.     const api_key = "RGAPI-";
  8.  
  9.     // Set the options for the https request
  10.     const options = {
  11.       hostname: event['pathParameters']['region'] + ".api.riotgames.com",
  12.       port: 443,
  13.       path: "/lol/summoner/v3/summoners/" + event['pathParameters']['id'] + "?api_key=" + api_key,
  14.       method: "GET"
  15.     };
  16.  
  17.     // Make the https request
  18.     const req = https.request(options, (res) => {
  19.         let body = '';
  20.         res.setEncoding('utf8');
  21.         res.on('data', (chunk) => body += chunk);
  22.         res.on('end', () => {
  23.             let response = {
  24.                 "statusCode": res.statusCode,
  25.                 "headers": {
  26.                     "Access-Control-Allow-Origin": "*",
  27.                     "Access-Control-Allow-Headers": "Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token",
  28.                     "Access-Control-Allow-Credentials": true,
  29.                     "Content-Type": "application/json"
  30.                 },
  31.                 "body": body
  32.             }
  33.             callback(null, response);
  34.         });
  35.     });
  36.     req.on('error', callback);
  37.     req.end();
  38. };
Add Comment
Please, Sign In to add comment