Cakephp REST integration with iPhone app - php

I'm developing backend system for iPhone app providing JSON data for each request for iPhone app. This is Cakephp based backend system and I was wondering if there was a good Cake way to receive POST request?
I understand using Router::mapResources(), Router::parseExtensions(), requestHandler component, Xml and Javascript helper is the correct way of creating RESTful application? If so, I was wondering how we could set them up to accept POST requests and potentially XML and/or JSON aswell.
Thank you

I was wondering if there was a good Cake way to receive POST request?
send a POST request to the correct url, and you can process it as normal. The POST data is in $this->data in the controller.
If so, I was wondering how we could set them up to accept POST requests and potentially XML and/or JSON aswell.
XML and JSON are not in the same category as POST. Read about REST setup here

Related

php codeigniter rest api how to deal with images with put method best practice?

I am developing a api using codeigniter for user signup and user update profile.
I have image field in form. To create user i have used post method which works fine.
But issue i am getting when i am updating user. I know that with put request we have to send urlencoded or json data. But what should i do to update image?
Should i make 2 request? One with normal url encoded data (PUT request) and one with post request (Update image).
In rest api development which is the significant way to deal with these type of request?
can anyone help me?
You can try Advance Rest API plug-ins or browser extension, or you can try postman software for testing api with multipart-formdata (images)
enter image description here

How to accept post variables send from other domain php?

one of my vendor he is asking a posting page where he can send some varaibles from his portal which is in asp.net.
My website is in php. what posting page i should be providing him and how to fetch whatever he is sending.
You may disable the CSRF validation (if you have any) to achieve this task.
However the standard way is to create webservice to achieve this goal.
The best and easiest API to implement is RESTful.
Here is reference to that:
How to create a simple REST API in PHP
Creating a simple REST API in PHP
It doesn't matter what language the vendor use or what you use...
He need to you to specify him what is your script URL that you allow him and expect POST request from him to do what he need.
If it's from his server side (for example in PHP we use curl),
so he need to use asp.net way to post request...
maybe this will help him how to do it
How to make HTTP POST web request
If he doing those request from client side (ajax),
so he can use jQuery http://api.jquery.com/jquery.ajax/
and in your side to allow in the php script the "access control allow origin"
see:
how to bypass Access-Control-Allow-Origin?

How do I pass php form data to an angular2 app?

I'm still quite new to angular2/4 so forgive me if I'm missing something obvious.
I am trying to update a booking process and we are doing this with angular2/4. Currently the booking process starts on a php website, once some basic information is filled out the angular app is supposed to take over. What I'm not sure of is how I'm supposed to take the form data from PHP and receive that data in my angular app.
There is an express.js back end for the angular app, but I don't understand how I would be able to post from the PHP site and return the result to the angular app.
Again sorry, I'm still new to angular so I'm not sure how I should approach this.
Create an API (http://localhost:8080/bookings/) in your existing PHP application which your angular app can access via a GET/POST request using angulars HTTP client. https://angular.io/guide/http.
Or
Alternatively, use the express backend to talk to the MySql DB / Or other DB that your php application is using. Use express as an API similar to the above or simply render the page with the data obtained from the DB. https://expressjs.com/en/guide/database-integration.html

Is there any way to dynamically submit a post to Facebook with PHP/ Laravel?

I am developing a web application that having a blogs section.
My client requirement is that he want to submit the blog post to facebook after inserting to DB.
That means automatically needs to post in Facebook with web application.
My Doubts are,
Is there any possibilities in this ?
If Yes, How can we done with PHP ?
Thanks.
You need to use the facebook graph api.
At https://developers.facebook.com/docs/pages/publishing you can read more about it.
Basicly, right before or after your db insert you should uae the api to post it to the facebookpage by sending POST request with proper parameters.
http://php.net/manual/en/function.stream-context-create.php
You can use this to send these POST requests

How to handle PUT and DELETE HTTP request in a PHP API First App?

I am wanting to build an API first RESTful application in PHP. I have never attempted to do this so I have some questions about how to handle PUT and DELETE
So for an example if I have a API endpoint that updates a User profile, should I make it accept BOTH a POST and PUT Request?
If I was building a Client for my API as a Desktop app or iOS app, etc it would be easy to send a PUT request to my API but I plan to have a Web based app for my API as well.
So on my web based app, I would have an HTML Form to Update a User profile, this would then be sent as a POST as HTML Forms do not allow PUT requests.
Could someone with more experience with this explain the best way to handle my example scenario?
Would the proper way be to send my Form as a POST to my PHP script, then my PHP script would make a proper PUT request to my PHP API with cURL?
You can absolutely also do PUT requests from browsers, but you need javascript.
Generally I would say a good way to think about it, is as follows:
First build a great REST api that follows all the rules. Only once you are at that point, think about the workarounds you need to make it work in other contexts. Submitting an HTML form is a valid thing to need a workaround for.
However, since 'POST' is completely open for interpretation, and has little rules associated, one option would be to create a single resource (or url) on your server that handles all the POST requests coming from browsers. (something like /browserpost).
You could always add a hidden <input> field with name="url" that specifies which resource was actually intended to be updated, and an <input> with name="method" value="PUT" for the intention.
You will need to add CSRF protection anyway, so I feel this would be a solid way to deal with this this. 1 endpoint to specifically 'proxy' html-based form submissions and internally do the appropriate mappings to the correct REST services.
I would use GET POST PUT DELETE as they are described in HTTP. That's restful (in my opinion). As regular browser forms does not support this I would send the data via AJAX.
If you really need to use browser forms, maybe because javascript is not enabled, then using POST requests with a param like ?method sounds like a suitable solution - although I don't like it.

Categories