{"id":20706519,"url":"https://github.com/pythoncoderunicorn/api_intro","last_synced_at":"2025-09-02T13:41:48.136Z","repository":{"id":151330291,"uuid":"623189015","full_name":"PythonCoderUnicorn/API_intro","owner":"PythonCoderUnicorn","description":"my repo for learning APIs","archived":false,"fork":false,"pushed_at":"2023-04-05T20:16:21.000Z","size":1781,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-17T20:24:36.668Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PythonCoderUnicorn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-03T21:55:55.000Z","updated_at":"2023-04-05T18:53:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"64cae869-9500-4411-af78-deb1c00caef6","html_url":"https://github.com/PythonCoderUnicorn/API_intro","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PythonCoderUnicorn%2FAPI_intro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PythonCoderUnicorn%2FAPI_intro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PythonCoderUnicorn%2FAPI_intro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PythonCoderUnicorn%2FAPI_intro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PythonCoderUnicorn","download_url":"https://codeload.github.com/PythonCoderUnicorn/API_intro/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242974132,"owners_count":20215275,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T01:23:37.022Z","updated_at":"2025-03-11T05:18:29.410Z","avatar_url":"https://github.com/PythonCoderUnicorn.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# API\n\nmy repo for learning APIs\n\n\n### RapidAPI\n\n- https://rapidapi.com/products/build-apis/\n\n- `https://jsonplaceholder.typicode.com/posts`\n\n\nGET `jsonplaceholder.typicode.com/posts`\n\n### FastAPI\n\nhttps://fastapi.tiangolo.com/\n\n\n\ninstall FastAPI\n```\npip install fastapi\n```\n\nrun fastapi \nhttps://fastapi.tiangolo.com/deployment/manually/\n\n\n\n## RapidAPI Studio\n\ncreate an API private thuses an API \n\n`https://zoo-animal-api.herokuapp.com/`\n\n`https://rapidapi.com/unicornapi/api/earth-animals`\n\n\n\n## climate change api\n\nto install a node version `nvm install v0.x.x`\n\n`npm init`\n\n`npm install cheerio`   ( version in tutorial 1.0.0-rc.10 )\n\n`npm install express`   (version in tutorial 6.17.1 )\n\n`npm i axios`           (version in tutorial 0.21.4 )\n\n`npm i nodemon`\n\n\n\n\n### initial setup\n\n\nchange in package.json\n```\n\"scripts\": {\n    \"start\": \"nodemon index.js\"\n  }\n```\n\nindex.js\n```\nconst PORT = 8000\n\nconst express = require('express')\nconst axios = require('axios')\nconst cheerio = require('cheerio')\n\nconst app = express()  // call the library as app\n\napp.listen(PORT, () =\u003e console.log(`server is running on PORT ${PORT}`))\n```\n\nthen to run program : `npm run start`\n\ncheck in browser : `http://localhost:8000/`\n\n\n### part 2\n\n```\nconst articles = []\n\napp.get('/news', (req, res) =\u003e {\n  axios.get('https://www.theguardian.com/environment/climate-crisis')\n    .then((response) =\u003e {\n      const html = response.data \n      // console.log(html) // raw html \n      const $ = cheerio.load(html)  // allows for elements\n\n      // find all a tags that have climate \n      $('a:contains(\"climate\")', html).each(function () { // callback function\n        const title = $(this).text()\n        const url = $(this).attr('href')\n\n        articles.push({\n          title,\n          url\n        })\n      })  \n      res.json(articles)\n    }).catch((err) =\u003e console.log(err)) \n})\n```\n\n### part 3\n\n```\n//------------ select specific articles from specific paper\n\napp.get('/news/:newspaperId', async (req, res) =\u003e {\n  // console.log(req.params.newspaperId)\n  const newspaperId = req.params.newspaperId \n\n  const newspaperAddress = newspapers.filter(newspaper =\u003e newspaper.name == newspaperId)[0].address\n  // console.log(newspaperAddress)\n  const newspaperBase = newspapers.filter(newspaper =\u003e newspaper.name == newspaperId)[0].base \n  \n  axios.get(newspaperAddress)\n    .then(response =\u003e {\n      const html = response.data\n      const $ = cheerio.load(html)\n      const specific_articles = []\n  \n        $('a:contains(\"climate\")', html).each(function () { // callback function\n          const title = $(this).text()\n          const url = $(this).attr('href')\n          specific_articles.push({\n            title,\n            url: newspaperBase + url,\n            source: newspaperId\n          })\n      })\n      res.json(specific_articles)\n    }).catch((err) =\u003e console.log(err))\n    \n})\n\n```\n\n\n\n\ntutorial had : climatechangeapi.herokuapp.com \n\n\n\n\nclimate change API\n\n\n## Render \n\nNew + \u003e new web service \nnpm run build\n\nhttps://climatenewsapi.onrender.com","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythoncoderunicorn%2Fapi_intro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpythoncoderunicorn%2Fapi_intro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythoncoderunicorn%2Fapi_intro/lists"}