{"status":false,"error":"Unknown method"} in codeigniter - codeigniter

I've managed to setup the REST ful API in my Codeigniter Application.name of controller and name of method are different but {"status":false,"error":"Unknown method"} error was display,how to solve?

Call the domain/index.php/controller/function without the "_get" .For example if your controller is called api and the function is users_get, use the address
localhost/domain/index.php/api/users.
That should work fine.

Related

Laravel, api, postman

I am following a grafikart tutorial on the back-end of an API under laravel, but creating a comment module, and since yesterday I have this message why. I think that I come from a call or from a space name but I know ... on postman also it returns to me errors.
postman:
error message:
Add the model namespace to your call, make sure you have a method called allFor
$comments = \App\Comment::allFor();

Resource controller functions are not triggered when using the main route in laravel

I am building a web app, and I want to use the resource controller but when I try to go to /$id,it should run the show method but it simply returns a 404 error.
I have defined the route as the main root as,
Route::resource('/','StoresController');
Now, when i use the following route, it works just fine and all the methods work just fine too.
Route::resource('store','StoresController');

doing post call to controller from other php file

I have a file that i added to my autoload file and i am trying to do a call to a controller function.
The problem is that this function is also called from my .js files and the method i want to call is accepting Input variables which i passed on with tha ajax call. Now my question is how i can call the controller from another php file and pass in post variables.
I can use the Route::post method but how can i pass post variables?
I was told that i can do it through the ioc but i have no idea how this would work.
Thanks
Route::post() is used for registering routes in your app.
Laravel comes with a Client class (from Symfony) that you can use for requests to an url.
But if you want to call a method from another controller, just do $res = FooController::method();

Parameter format issue with ASP.NET Web API controller

I am watching this pluralsight demo video on Web Api, and he is using fiddler to pass in a parameter using Http Get with the syntax of controller/parameter
So he's using http://localhost:2405/api/values/5
5 Is the parameter he's passing in.
In my code, I have everything set up exactly the same way he does... with a routing template of {controller}/{id} and a controller method with a signature of
public string Get(string zipcode)
I can pass a parameter just fine with http://localhost:2405/api/values?zipcode=25252 but if I try passing in a paramter the way he does, like http://localhost:2405/api/values/25252 I get an error saying I do not have an action available to handle that request on the controller.
What is he doing right, that I'm doing wrong?
You need to change your routing template to {controller}/{zipcode} as the name of the parameter must match the name in the template.

Web API get route values

Is there any way to statically get route values from a service method (outside of a controller) that is running in a Web API context? For example, I can do the following in ASP.NET MVC:
var mvcHandler = HttpContext.Current.Handler as MvcHandler;
var routeValues = mvcHandler.RequestContext.RouteData.Values;
I'd like to find the equivalent version of this code for Web API.
When I try to debug a sample Web API request and look at HttpContext.Current.Handler it is of type HttpControllerHandler, but this type doesn't have any properties to access route data.
EDIT
To try to help provide some more information. The code I am trying to read the value from is inside of a factory class I have that builds a custom object for my application.
You can use GetRouteData() extension on HttpRequestMessage. You would need to include System.Net.Http namespace to get this.
System.Web.Http.Routing.IHttpRouteData routeData = Request.GetRouteData();
I was able to find a solution that would get the route values for either an MVC request or a Web API request.
HttpContext.Current.Request.RequestContext.RouteData

Resources