Welcome Guest, Not a member yet? Register   Sign In
Using Codeigniter as RestAPI (using Axios)
#1

Hello, I'm trying to use Codeigniter 4 as a RestAPI, but I'm encountering an high number of problems. Some of them are strangely omitted in the docs (and I can't search in the forum because there's a bug in the search at the moment).

I'm using Axios to contact the server.

1) How does validate() work? I can't find the details in the docs and I can't understand what data validates and if there's a way to submit custom data to validate (and I need this really hard)

2) I can't work with axios.put. For some reason it doesn't populate the $_POST correctly. 
 - If I send a JSON with 'Content-Type': 'application/json' , php://input has the JSON but $this->request->getRawInput() give me this: $varname[{"lorem":"ipsum"}] => null
 - If I send a FormData, I get this monstrosity: [------WebKitFormBoundarygAazo6HBmB477LPA Content-Disposition:_form-data;_name] => "lorem"

3) to do some tests with localhost to real server I had to add some extra junk code because header('Access-Control-Allow-Origin: *'); in the public/index.php doesn't work alone. I need to use $this->response->setHeader in the Control too.


P.S: My code is a total mess of tests, I don't really have something to show.
Reply


Messages In This Thread
Using Codeigniter as RestAPI (using Axios) - by shinseiten - 10-01-2020, 03:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB