swapi icon indicating copy to clipboard operation
swapi copied to clipboard

Change URL protocol in response data based on whether the request was made over HTTPS

Open mulchy opened this issue 9 years ago • 1 comments

Hi!

First, I would like to say that I love this project and I use to teach my students about APIs. It's awesome!

Second, I have a small feature request. Could we detect on the server whether the user-agent made the request over HTTPS and update any URLs in the response data to use HTTPS as their protocol?

Currently, running curl https://swapi.co/api/films/ results in

{
    "count": 7,
    "next": null,
    "previous": null,
    "results": [{
        "title": "A New Hope",
        ...
        "species": ["http://swapi.co/api/species/3/", "http://swapi.co/api/species/2/", "http://swapi.co/api/species/1/"],
        "created": "2015-04-17T06:51:30.504780Z",
        "edited": "2015-12-17T14:31:47.617768Z",
        "url": "http://swapi.co/api/films/7/"
    }]
}

I am proposing a desired output of

{
    "count": 7,
    "next": null,
    "previous": null,
    "results": [{
        "title": "A New Hope",
        ...
        "species": ["https://swapi.co/api/species/3/", "https://swapi.co/api/species/2/", "https://swapi.co/api/species/1/"],
        "created": "2015-04-17T06:51:30.504780Z",
        "edited": "2015-12-17T14:31:47.617768Z",
        "url": "https://swapi.co/api/films/7/"
    }]
}

mulchy avatar Oct 19 '16 21:10 mulchy

Hey @mulchy thanks for getting in touch. Good to know it is being put to good use!

I'd love to do this change. It shouldn't be hard to do actually, I believe the Base URL is hard coded, so a minor change would update this easily. Reckon yourself or a student of yours is up for doing this first pull request? Happy to guide you.

phalt avatar Oct 24 '16 09:10 phalt