gerkintrigg Posted December 31, 2009 Share Posted December 31, 2009 If I want other people to access my PHP code from THEIR website, do I need to write a clever API handler, or is there a simple way of allowing other people to access it? (I had a look and thought this was the most likely forum, so sorry if it needs moving.) Any suggestions welcome. Quote Link to comment https://forums.phpfreaks.com/topic/186789-writing-an-api/ Share on other sites More sharing options...
Mchl Posted December 31, 2009 Share Posted December 31, 2009 If you want other peopple to access your code, just put it up as a download on your site. Unless what you mean is, you want other people to be able to access functionality provided by your code. Yeah, that's what API is for. Quote Link to comment https://forums.phpfreaks.com/topic/186789-writing-an-api/#findComment-986382 Share on other sites More sharing options...
gerkintrigg Posted December 31, 2009 Author Share Posted December 31, 2009 Sorry Mchl, yes - I want them to access the functionality, but not the code itself. As far as I see it, there will need to be 2 parts to it... One for my side, that resides on my server so that the API app can plug into it and one for the client, which will need to be able to interface with the web server. How does one go about starting to write an API? Is it able to be done in PHP and if so, are there any tutorials on how to get started? I once wrote something back in the 90's in Object Pascall which interfaced with a web server, but that was before PHP hit the big-time and it used a JAVA engine, so I'm a bit clueless... it was a LONG time ago... Quote Link to comment https://forums.phpfreaks.com/topic/186789-writing-an-api/#findComment-986407 Share on other sites More sharing options...
oni-kun Posted December 31, 2009 Share Posted December 31, 2009 Why not make it simple for the user, and output xml/JSON of the information they're using? You should have sufficient room for functioning, but not 100% sure the scope of what you're wanting to do it for. Quote Link to comment https://forums.phpfreaks.com/topic/186789-writing-an-api/#findComment-986410 Share on other sites More sharing options...
ChemicalBliss Posted December 31, 2009 Share Posted December 31, 2009 Without any knowledge on specifics for API's; I would use this method: 1. Create a script that uses special codes and restrictions, so only it's "Clients" can access functionality. 2. Use the script like so: Webserver sends a request using a "Client Class Object" (that you create for your clients), that sends either a POST or GET type request (POST is preffered). In the form of: http://ip.add.re.ss/clientAPI/?method=[CLASS::METHOD]¶m1=[Data]¶m2=[Data]&... The page would output the response, and the Client script would read it as the result. Alternatively you could risk using EVAL() (Highly Risky), if though, you do you eval, you can send arguments in raw php code, to be executed by the script. Though if any security issues arose from this method you could lose your entire server (not just your website). Other than that, i wouldn't be able to help you im afraid, but good luck i'll keep an eye on this thread . -CB- Quote Link to comment https://forums.phpfreaks.com/topic/186789-writing-an-api/#findComment-986418 Share on other sites More sharing options...
Mchl Posted December 31, 2009 Share Posted December 31, 2009 Rememberm that API is a very general term, and there might be many specific implementations. For web application API is handled through POST/GET requests. The client will send to your server a request (usually specyfing some action to perform, any input data if needed and optionally an 'API key' if the service is for authorised users only. Your script does its job, and hands the results back to the client. Now, whether it'll be JSON, XML or even plain text, is up to you. If you have some experience with AJAX, you might find it familiar. An AJAX application is basically a JavaScript application on client side that uses API to communicate with server side applicaiton. Quote Link to comment https://forums.phpfreaks.com/topic/186789-writing-an-api/#findComment-986483 Share on other sites More sharing options...
abazoskib Posted December 31, 2009 Share Posted December 31, 2009 There are different ways to approach this. It all depends on your needs. You can do a simple POST/GET API like suggested above. You could also have a RESTful API where parameters get passed like: http://yourdomain.com/param1/param2/param3/ (this will need mod rewrite rules on your server). You can do a combo of POST/GET and REST by POST/GET to a URL like the one I showed above. You can also look into a SOAP server. There is VERY LITTLE documentation on this, and it was such a pain to setup the WSDL for it. I wrote one a few months ago which works really well, but be warned its very challenging. If I had to do it again I would use REST combo with POST/GET. Quote Link to comment https://forums.phpfreaks.com/topic/186789-writing-an-api/#findComment-986498 Share on other sites More sharing options...
Mchl Posted December 31, 2009 Share Posted December 31, 2009 And don't forget to learn lots of acronyms Quote Link to comment https://forums.phpfreaks.com/topic/186789-writing-an-api/#findComment-986516 Share on other sites More sharing options...
gerkintrigg Posted December 31, 2009 Author Share Posted December 31, 2009 thanks a lot for this info. I'll try the REST suggestion and let you know what happens. Quote Link to comment https://forums.phpfreaks.com/topic/186789-writing-an-api/#findComment-986518 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.