Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8950713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:30:06+00:00 2026-06-15T13:30:06+00:00

I developed a very quick and simple PHP application for reading classified ads from

  • 0

I developed a very quick and simple PHP application for reading classified ads from an XML file and allowing the user to perform CRUD operations on it (this was a homework assignment).

I’m now tasked with developing this application to a RESTful service. The professor actually doesn’t seem to have any experience with RESTful services, because he said my application was find to hand in for the next assignment, when my research indicates it doesn’t really fulfil all the RESTful requirements.

Regardless, I want to do this correctly for learning purposes, even if I can hand in my old assignment and get a good grade. I’m having trouble learning where to begin though; I’m not sure exactly what a RESTful service really is.

I think the best way to get advice is to post sample code from my previous assignment to see how I handled things and how I need to handle things instead.

For instance, here is how I create new classifieds.

Create.php

//Basically just a list of <INPUT TYPE = "text" NAME = "something"> in the <body> fields

CreateSuccess.php

<html><head><?php $simplerXML = simplexml_load_file('file.xml'); 
//Generate the basic ad information
$newAd = $simplerXML->addChild('advertisement','');
$newAd->addAttribute('category', $_POST["category"]);
$title = $newAd->addChild('title', $_POST["title"]);
$title->addAttribute('ID', $_POST["ID"]);
$pageTitle = $newAd->addChild('pagetitle', $_POST["pagetitle"]);
//etc, for all the SUBMIT boxes

//save the XML
$simplerXML->asXML('file.xml');
echo "<script type='text/javascript'>
//redirect back to ad listing page
window.onload = function () { top.location.href = 'ads.php'; };
</script>";
?></head>
<body></body></html>

I’m also using URL parameters for the RUD actions. I’ve heard URL parameters are not allowed as well?

Thanks.

EDIT:
So the SWITCH statement, does it go in the index.php file? And then each case will call a function, ie CreateXML for the POST method?
Then the parameters it needs will be the object type, object id, and content type? How do I get the values to update the XML with, do I just send it to the Create.php file containing the list of input boxes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:30:07+00:00Added an answer on June 15, 2026 at 1:30 pm

    If your service supports all CRUD operations, it’s always advisable to implement a RESTful interface. It’s not super-hard to do so. I’ve outlined some of the basics below.

    A RESTful service simply does a few things:

    1. It uses HTTP request method for communication of the CRUD action
    2. It uses HTTP status code to communicate response status, and
    3. It uses the URI to define your resource (file, database item you’re accessing, etc).
    4. It is stateless

    The idea is to minimize the development of custom communications for these things that are already defined in the HTTP spec.


    1 – REQUEST METHOD

    The 4 HTTP request methods you’re required to support for a RESTful service are:

    1. POST
    2. GET
    3. PUT
    4. DELETE

    and you may optionally support

    1. PATCH
    2. HEAD

    You can map these directly to your CRUD actions as follows:

    • POST = Create
    • GET = Retrieve
    • PUT = Update
    • DELETE = Delete
    • PATCH = Edit (a partial update, e.g. “change password”. PUT becomes “replace”)
    • HEAD = Header only (metadata about the resource)

    To do this, route requests properly with a simple request method router as follows:

    switch ($_SERVER["REQUEST_METHOD"]) {
        case "POST":
            // Create action
            break;
        case "GET":
            // Retrieve action
            break;
        case "PUT":
            // Update action
            break;
        case "DELETE":
            // Delete action
            break;
    }
    

    2 – STATUS CODE
    You should further implement HTTP status codes from your service to communicate status back to the client, e.g.:

    • 20x = success
    • 30x = redirection
    • 40x = communication issues
    • 50x = server error

    To do this, simply prepend your response with the proper HTTP header output, e.g.:

    header("Status: 500 Internal Server Error");
    

    You can reference the full list of implemented HTTP status codes here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html


    3 – URIs
    For URIs, RESTful services usually follow a top-down approach to categorized naming, e.g.

    /object_type/id.content_type
    

    Examples:

    POST /user
    PUT /user/1
    GET /user/1.json
    GET /user/1.html
    

    You can implement a very rudimentary RESTful router for the above convention using Apache with mod_rewrite in an .htaccess file, as follows:

    RewriteEngine On
    RewriteRule ^([^\/]+)\/([^\.]+)\.(\w+)$  index.php?object_type=$1&object_id=$2&content_type=$3
    

    You would then have index.php Look for the appropriate object_type and id to route appropriately, e.g.:

    $object = $_GET["object_type"];
    $id = (int) $_GET["object_id"];
    $content_type = $_GET["content_type"];
    
    // Route from here to a class with the name of the object (e.g. UserController) via __autoload
    // or to a file (e.g. user.php) via include, and pass id and content_type as params
    

    4 – STATELESSNESS
    Simply stated, the server maintains no “state” for the client. No requirements for storing session or status. Each request represents a complete transaction. I.e. if I GET user/1, the server won’t remember that I did that, and future requests won’t be dependent upon or affected by previous ones.

    If you implement these standards, congrats, you’ve built a RESTful service!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i developed a very simple vb.net application and i need a way for every
I've developed a very simple ASP.NET (jQuery) application. The RDBMS is MS Sql Server
I have developed a simple location aware iPhone application which is functionally working very
I have developed a very simple Android app where user has to select items
I've developed a very simple host and client which I wanted to use to
I have a very simple windows Service that is developed in vb.net 2008. When
I am very new to iPhone. I have developed two version of an application
I developed a web application Using java EE 6, its a very small web
Quick question: I have a very busy form going on that I have developed
I'm making my first attempt at experimenting with Comet. I developed a very simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.