PHP Tutorial PHP HOME PHP Intro PHP. PHP file() Function Complete PHP Filesystem Reference. Definition and Usage. The file() reads a file into an array. This post will teach you how to create a simple REST API in PHP. This source code will be used for our series of JavaScript programming tutorials. ├────── read.php - file that will output JSON data based from 'products' database records. BUT if you need to download this PHP REST API source code only, you can do it using.
Active4 years, 9 months ago
I'm working on getting a basic RESTful API example. Currently I'm using the example I found here however it has some bugs and is incomplete.
I've already added the following lines to my .htaccess as the example stated.
My problem however is simply getting the concrete class of mine to print '12'. I don't know which URL to visit to get the message '12' to be shown on the screen.
Download File Php Example
Here is my abstract class code:
And here is my concrete class code (trouble on line 8):
As you can see line 8 on the concrete class (in the constructor) never gets printed. Currently I'm trying to make my example work by going to:
Prix16.3k1212 gold badges5656 silver badges116116 bronze badges
John CrawfordJohn Crawford3,63288 gold badges2323 silver badges3434 bronze badges
2 Answers
Not sure if you still need an answer on this, but I just got mine working, with a few tweaks. There are a few problems with your setup. First is the .htaccess file. You have it pointing to MyAPI.php, but if you read the tutorial, he actually has a third file, api.php, that instantiates the MyAPI class. The line:
should be:
You shouldn't be trying to access the MyAPI.php file directly. Rather, apache should point to api.php, passing the request details along. The contents of the api.php file (per CM's site) are:
The second problem is with your URL - you should follow his example of passing an endpoint (in his/my case, /api/v1/example). This will produce both the text inside the MyAPI constructor (if you leave that in yours), and the message from the example endpoint function. For what it's worth, I stripped out all of the key and user stuff just so I could get it running. So my MyAPI.php file looks like:
![Rest Download File Php Example Function Rest Download File Php Example Function](/uploads/1/3/3/2/133282356/466486624.gif)
I took the 'start simple, dress it up later' approach. Good luck!
MJacobsenMJacobsen
In my opinion this URL is against REST principles
If one mentions in the url
A RESTful url should be something like
request=get
then the purpose of using HTTP GET dies.A RESTful url should be something like
Rest Download File Php Example Functions
and a HTTP GET request to this url should do the work.
k0pernikus21.5k2828 gold badges125125 silver badges214214 bronze badges
UmairUmair