Coder Social home page Coder Social logo

saketkothari / api-proxy-server Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 32 KB

Utilizing Node.js and Express to create a server for enhanced security with hidden API keys, rate limiting, and efficient caching to optimize API performance.

JavaScript 69.12% HTML 12.33% CSS 18.55%
api-proxy expressjs open-weather-api rate-limiting apicache

api-proxy-server's Introduction

Node API Proxy Server

  • Server used for hiding API keys, rate limiting and caching.
  • This uses the OpenWeather API but you can easily change it to whatever public API you are using.

In this we can hide our public API keys by using our own server because in a lot of cases when you use a third-party API like the Github API or Twitter or in our case we're going to be using Open Weather API, a lot of times you need to include your API key directly in the url when you make your request So here I have a very simple just client-side Vanilla JavaScript Weather app that uses Open Weather API and we can just put in a city name and it just you know gets the the temperature but if I open up my source code here and I look in my main.js you'll see that in this fetch weather function I'm making a request directly to open weather map and I have my API key or my app id directly in my client-side code which you really don't want to show.

So there's a few ways around this and in one way is to just have your own server your own API proxy server which is kind of like a middleman that you can make requests to and then store your API key on the server so that's what I want to do and in addition to that how we can add things like rate limiting so people can only make a certain amount of requests per a certain amount of time and we'll show you how to add some caching.

Usage

Install dependencies

npm install
npm run dev

Add public API info

Rename .env.example to .env and edit the values

If the public API URL is https://api.openweathermap.org/data/2.5/weather?q={city}&appid={APIkey}

You can add on any other query params as needed when hitting the /api endpoint such as https://yourdomain/api?q=detroit without having to add your key in the client

  • Add new routes as you see fit
  • Change rate limiting and caching to desired values

api-proxy-server's People

Contributors

saketkothari avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.