.net core api project routing issue - rest

I am new to .net core and not very good with the routing understanding. I am trying to make api calls using the route template as follows
routeTemplate: "api/{controller}/{action}/{id}"
When I created the .net core project of api type, it added a controller with the name of Values and the way its accessing the api calls is placing the routes on top of the controller.. [Route("api/[controller]")]
How can I set my controller to use the action step?
I basically want to be able to make calls to my api like this
https://localhost:44345/api/MyProcessor/getValues
https://localhost:44345/api/MyProcessor/AllDefinations
Where MyProcessor is the name of the controller.

You want to make calls to your api like:https://localhost:port/api/[controllerName]/XXX.
1.If the last XXX is defined to action. There are two options as
follow:
Change the [Route] template:
[Route("api/[controller]/[action]")]
Change [HttpGet] which is based on [Route("api/[controller]")]:
[HttpGet("[action]")]
2.If the last XXX is defined to any other name. You could change the [HttpGet] which is based on [Route("api/[controller]")]:
[HttpGet("getValues")]

Related

How to get user related data with Generic Interface in OTRS 6?

I wonder how to get User Data with Generic Interface. It seems that there is no Controller to get User Data...
these are the only controllers:
So how can I add user methods to my webservices?
I tried adding a User section in my webservice.yml and reimported it:
User:
Description: Search for User Data
MappingInbound: {}
MappingOutbound: {}
Type: Kernel::System::User
but that didn't work. OTRS says that there is no Controller for Kernel::System::User. I also tried only to set Type to User. Same error.
Since the generic interface replaces the deprecated RPC.pl API, it should have at least the same set of methods.
Otherwise this would'nt be an improvement of the API right?
You can create controller by youself, it's not that hard.
Take a look at existing services in Kernel/GenericInterface/Operation/*
Register new operation with XML, look for examples here: Kernel/Config/Files/XML/GenericInterface.xml
Don't forget to call:
/opt/otrs/bin/otrs.SetPermissions.pl (as root)
/opt/otrs/bin/otrs.Console.pl Maint::Config::Rebuild
after creation of new files

Jira calls external REST Service

My Problem: I want to introduce a new field in JIRA with status information from external REST Service (response is json).
Plan: Every Jira issue has a input field with some reference string. Behind this field there should be a panel, what should display informations from the external REST call (parsing response JSON is required).
Can someone give me some good info pages, how to tell JIRA to call external REST Service?
If you don't want to build it see:
nFeed
HTTP Feed Custom Field
If you want to build it yourself then start by following this tutorial on Creating a custom field type which is to more or less store a basic String within the database. (This would be the reference string)
You then have two options, the first is within the JiraCustomField class override the getVelocityParameters which was taken from How to call a java method from velocity Atlassian Answers question.
Then create a method (fetchValueFromWebService(String val)) that you would call that would contain code to query the REST Service based off the fields value that would be passed in from the velocity template. (E.g. $instance.fetchValueFromWebService($value))
To perform the actual web service call you can use any library you want, just see the Managing Dependencies documentation so it gets included in the plugin. (For example using the Jira Jersey version see this)
Your other option would be to within the view-basictext.vm have it use javascript and perform an AJAX to the web service by calling a function in your own JS file and dump that into a span that you have defined: (See Including Javascript and CSS resources)
<span id="webServiceValue"></span>
<script type="text/javascript">
fetchValueFromWebService($value);
</script>
You would however need to ensure that the webservice has Cross-origin resource sharing (CORS) enabled if you go the AJAX route.

Can grails application have RestController and normal controller (for GSP) for same domain class

Recently I need to create REST API for existing grails application.
I am thinking that is it really possible to have both of the controllers (Normal and Restful) for same domain class in one single grails application?
Which controller will handle the request if make a HTTP GET request?
Please discuss your thoughts or if it is possible at all please guide me how.
We can define a new Controller to handle to REST API calls. e.g. In my app I have User as Domain Class and have UserController which return the data to GSP pages. I wanted to add REST API support (unfortunately) in the same app and I don't wanted to deal with mess it is already there in UserController. So I added new Controller UserRestController which will specifically handle the REST API calls and following mapping in UrlMappings.groovy which now works fine. Thanks to #codehx for helping me on this.
"/api/users"(controller: "userRest", parseRequest: true) {
action = [GET: "list", POST: "save" }
"/api/users/$id"(controller: "usersRest", parseRequest: true) {
action = [GET: "show", PUT: "update", DELETE: "delete"] }
Which controller will handle the request if make a HTTP GET request?
As far as it is not possible to have two controllers with same name in grails app this will not be confusing.
Just use two different names for Normal controller and for your RESTFUL controller, so obviously the URL for accessing the two urls will be different.

Asp.net Web API RouteTemplate for passing multiple parameters to a method

I am using the ASP.Net Web API and I need to pass in a different number of parameters to the accions in my controllers, but I haven't found (I'm new to Web API) a specific way to indicate a route template for the different methods I might have in my controllers.
Currently I have this template.
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
I don't think I'll have to indicate a new template for each of the different methods I have in my controllers, do I?
As I told you, I'm really new to Web API and I haven't found much info about this , that's why I'd really apreciate if you could give me some advice or guidance.
EDIT
It seems that the best way to go will be passing in the parameters in the query string like this:
api/controller/action?parm1=val1&par2=val2&par3=val3
the problem is that I have no idea how to put this in a route template or how to retrive these values from the query string.
Take a look at using The Route Attribute.
Attribute Routing

ASP.Net MVC 2 Forms Authentication cookieless = "UseUri" while submit authorization fails

I just started working with ASP.Net MVC 2.
I created a new ASP.Net MVC application and created one vehicle controler with a database table connected with LINQ. Then created forms authentication mechanism for the application and tried to use the uri instead of cookies it was working smoothly but when i submit the form by creating a "Create" view from the controler using the utility it just dont work. The autherization got failed and asking to enter the user name and password again.I had created the authorization mechanism by adding Authorise attribute to the Controller so as to get authorized for all the actions.
namespace MVCNEW.Controllers
{
[Authorize]
public class VehicleController : Controller
{
But if i use the cookies instead of uri it works fine.
Thanks in advance...
Please see http://forums.asp.net/p/1517391/3634908.aspx for an official response.
Summary: Cookieless Session support is essentially obsolete, and the MVC framework isn't likely to include additional support for it.
I found the problem and a solution.
This was due to some error in the framework. They are not creating the Uri string for the Form action while calling
Html.BeginForm()
But if we make it call overloading of this method like the providing the Controller name and Action name it is working fine.
view plaincopy to clipboardprint?
Html.BeginForm("Create","Vehicle")