-1

I am trying to access an API written in PHP through Swift. I have searched on the internet for a solution but am unable to find one. Forgive me if this is a stupid question, as I am new to both PHP and Swift (primarily a Java programmer).

So my question is: how do I go about using a PHP api in my Swift application? For example, an API like this: https://www.multicraft.org/site/docs/api. It provides functions and such, but I'm not sure how to call them from Swift.

  • This is a pretty broad question because there are lots of ways that an API can be implemented. It doesn't really matter what language the API was built in. The short answer is that you'll need to ask the developer of the API for documentation. – John Ellmore Aug 20 '18 at 19:27

1 Answers1

1

Disclaimer: I do not know the swift programming language.

It looks like you are getting a couple of things mixed up. The PHP API you're talking about is probably a REST over HTTP API. This means that you access the API by making HTTP calls which you can read about here. The programming language in which the api is written doesn't matter to the user of the API which is the fantastic thing about REST API's! There are some exceptions but don't worry about them.

In order to use your api you'll need to find some sort of end-point reference describing how to use the API. It will probably be full of links looking something like this:

http:://yourapi/users

In order to make an HTTP API call from swift see this code example.

More detailed information here

max meijer
  • 77
  • 5
  • For example, an API like this could be used: https://www.multicraft.org/site/docs/api. Is there a way to implement something like this into Swift or is this a REST over HTTP API like you were stating above? – Blockhead7360 Aug 20 '18 at 22:14
  • This appears to be more of a local API. It is a set of php functions that you can call locally from your own php script. It is not meant to be used over http. I'll see if I can implement an example for you. – max meijer Aug 21 '18 at 06:54