Victor Alarcon
Victor Alarcon

Reputation: 17

Change value from api response React

From a request call to the marvel API I receive the following

       {
        "id": 1011334,
        "name": "3-D Man",
        "description": "",
        "modified": "2014-04-29T14:18:17-0400",
        "thumbnail": {
          "path": "http://i.annihil.us/u/prod/marvel/i/mg/c/e0/535fecbbb9784",
          "extension": "jpg"
        },

How can I change the thumbnail.path to be https instead of HTTP because when I deploy the app I get the warning of mixed content saying it will be change automatically

Upvotes: 1

Views: 1102

Answers (1)

armin yahya
armin yahya

Reputation: 1496

You can change the value of response after response received. for example:

axios.get('/post?ID=12345')
  .then((response) => {
       const modifiedResponse = response.data;
       modifiedResponse.thumbnail.path = 
       modifiedResponse.thumbnail.path.replace("http", "https");
       // I see you tagged react
       this.setState({post: modifiedResponse});
  })

Please share more code if it seems my answer is ambiguous.

Upvotes: 3

Related Questions