Swift Call

HI,
is there a method to call the API from Swift in IOS please?

1 Like

Hi @kit_fisto

The API is a simple REST API. I don’t know any Swift myself but I’m fairly certain that it will have the capability to make an HTTP call. You probably need to consult the Swift language documentation

If you make an HTTP GET to https://api.rcpch.ac.uk/growth/v1 and include your API key in the headers then you should get back a JSON description of the API in openAPI3 format.

You can explore the API using something like Postman (using our Postman collection) and you can also use Postman to generate simple requests coded in a variety of languages including Swift.

The BaseURL should be included in the Postman Collection by default, but in case not, ensure you are hitting the API server https://api.rcpch.ac.uk/growth/v1.

Thanks.
I can make an HTTP call with apikey in Swift. I have used open weather before and add the city and units by adding &city=y&units=x etc to the call. The returns a JSON formatted return. Is there a format to do this?

For our API you send a POST request containing a JSON body. (We did try initially building the API to use data in the URL as a query string, but the amount of data we needed to pass to the API made the URLs too long)

this example JSON should return you a chronological_centile of 34 and corrected_centile of 82

{
    "birth_date": "2020-03-12",
    "observation_date": "2020-04-12",
    "observation_value": 54,
    "sex": "male",
    "gestation_weeks": 37,
    "gestation_days": 1,
    "measurement_method": "height"
}

I am guessing you are writing an iOS app for the API. If this is for your own learning/entertainment then go right ahead, but I just wanted to let you know that we are working on a React Native app, currently in pre-alpha, which will furnish us with an iOS and Android app which uses the API. We’re very happy for other people to get involved in helping build this. It’s open source and the code is here GitHub - rcpch/digital-growth-charts-react-native-client: A react-native client to render results from the digital growth charts api

Thanks- yes just wanted to get something to ‘help’ my IT department use the API!