Writing data from your Web Service – adding a POST endpoint to your component
We have defined two endpoints so far: the v1/invoices
and v1/projects
endpoints. For both endpoints, we have enabled the POST
request type so that users can create projects (implicit when using the createCRUDRoutes()
method) and invoices (we explicitly added the POST
route in our WebServices
plugin).
In the previous section, we already added the controller to handle projects. The Joomla! FrameworkTM is really useful when we abide by its structure and you may just try to create a project using the POST
request. We can test this by creating a post.php
script as we did with the get.php
script. So, create the Scripts/api/post.php
file with the following content:
<?php if (extension_loaded('curl') == false) { throw new \Exception('curl not installed'); } $url = 'https://YourSite.com/api/v1/projects/'; $data = array( ...