简体   繁体   中英

Override single API endpoint locally

Is it possible to override a single API end-point locally?

ie:

https://jsonplaceholder.typicode.com/todos/1

To this one:

http://localhost:3000/todos/1

But without touching others end-point like:

https://jsonplaceholder.typicode.com/movie/1

I'm trying to find a tool to do this, I also tried to use the hosts file but it work only domain by domain, not for a single API endpoint.

You can use the Map Remote function in Charles . I believe similar feature exists in other HTTP proxy tool such as Fiddler too.

First, configure Map Remote and mapping https://jsonplaceholder.typicode.com to http://localhost:3000 , limit the path to /todos/* , so that it won't impact /movie/1 :

在此输入图像描述

Then, as Charles is trying to intercept HTTPS site, you need to enable "SSL Proxying" and add jsonplaceholder.typicode.com (Otherwise, browser will ignore the interceptor or just throw a certificate warning):

在此输入图像描述

It's done. In browser, access to https://jsonplaceholder.typicode.com/todos/1 or https://jsonplaceholder.typicode.com/todos/2 will be redirected to http://localhost:/todos/1 or http://localhost:3000/todos/2 internally, while access to https://jsonplaceholder.typicode.com/movie/1 is not touched.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM