I'm attempting to migrate a Web API service to ServiceStack with minimum (no) change to the service definition, but am having trouble creating an operation with an array as the body parameter, like in the Web API service:
But if I use a DTO-array, like in the following, the operation disappears from Swagger:
A request class that inherits from a list of T should do what you want.
Eg
public class PatchCustomer : List<ApiCustomer>
{
}
Related
I want make Swagger specification for my API. But customers use my API can create and delete some entity on server. Each entity have only one type and can include other entity.
Example of API:
http:/localhost/api/<entity_lv_1>
http:/localhost/api/<entity_lv_1>/<entity_lv_2>
http:/localhost/api/<entity_lv_1>/<entity_lv_2>/<entity_lv_3>
And my rest controller have mapping /** for catch all of them.
I try make mapping with regexp:
#GetMapping(value = /{entityLv1}/{entityLv2:[a-z0-9_-]+/*})
But it not work fine, because server can't processed request with entity_lv_3 correctly.
Let's say I have some codes to make 2 rest calls to the other API. And I need a service layer to make 2 rest calls in the same action.
In Java, I probably would do something like this
#Service
public class RestService{
#Autowired
RestClient restClient
def shutdown(){
if(restClient.isSystemGood()){
restClient.shutdownSystem()
}
}
}
#Repository
public class RestClient {
boolean isSystemGood() {
...
}
void shutdownSystem() {
...
}
}
How should I fit in grails way to do the similar thing?
Should I put the logic inside RestClient into a domain class? or Should I put both RestService and RestClient into a domain class? Does domain class have to be backed by a DB?
Because I only see service and domain folders in the grails default file structure.
RestService (in your simple case a non-transactional one) inside grails-app/services directory is the right place for the logic. Inject the service inside the controller action to use it.
Injecting services into the domain class is not recommended. It hard to test, degrades the read performance and results in a spaghetti design. This is why Grails now by default, has disabled the services injection in the domain class
Some iPad client access my 'salesforce' application via pocketsoap frame work. Can any one please tell me whether that client can invoke (reuse) my Apex service methods with 'pocketsoap'. I have already exposed those methods as a WebServices as follow. Thanks.
// Job service
global class ServiceJob {
WebService static String jobConfirm(String jobId) {}
}
// Sample registration service
global with sharing class ServiceSampleRegistration {
WebService static Sample_Registration__c registerWS(Job_c job, ID userId) {}
}
This should be perfectly fine — if you go the list of Apex classes inside the Salesforce org you should see a link to the WSDL for your class next to the Edit link. You can use this as the basis for your SOAP calls to the custom web service methods.
I have succesfully implemented a RESTful Web Service using the .NET 4.0 framework with MVC 4 and the ApiController class.
I have a method, let's say GetMovies ("/api/movies") that returns an IQueryable<Movie>. Serialization is done using DataContractSerializer, of course. The problem is in the name of the returned list, because it is ArrayOfMovie:
<ArrayOfMovie>
<Movie></Movie>
<Movie></Movie>
...
<Movie></Movie>
</ArrayOfMovie>
I cannot create a custom class, let's say Movies, and add a [CollectionDataContract(Name = "movies")] annotation (as suggested at https://stackoverflow.com/a/4593167/801065) because I cannot extend IQueryable without implementing all of its methods. And I most definitely need an IQueryable for OData/jQuery processing.
How can I solve this? Is there an annotation that can help me?
This is the solution I found.
You need to put a group class in the main class you want to serialize.
[DataContract(Name = "movies")]
public class group
{
[DataMember(Name="movies")]
public IQueryable<Movie> Movies;
}
I am exploring the idea of implementing a web service api using WCF Data Services and EF4. Realizing that some operations require complex business logic, I decided to create a partial class the same name as the main EF data context partial class and implement additional methods there to handle the more complex business logic. When the EF context object is used directly, the additional method shows up (via intellisense) and works properly. When the EF classes are exposed through a WCF Data Service and a Service Reference is created and consumed in another project, the new method does not show up in intellisense or in the generated Service.cs file (of course, I updated the reference and even deleted it and re-added it). The native data methods (i.e. context.AddObject() and context.AddToPeople()) work properly, but the new method isn't even available.
My EF classes look something like this:
namespace PeopleModel
{
//EF generated class
public partial class PeopleEntities : ObjectContext
{
//Constructors here
//Partial Methods here
//etc....
}
//Entity classes here
//My added partial class
public partial class PeopleEntities
{
public void AddPerson(Person person)
{
base.AddObject("People", person);
}
}
}
There's nothing special about the .svc file. The Reference.cs file containing the auto generated proxy classes do not have the new "AddPerson()" method.
My questions are:
1. Any idea why the web service doesn't see the added partial class, but when directly using the EF objects the method is there and works properly?
2. Is using a partial class with additional methods a good solution to the problem of handling complex business rules with an EF generated model?
I like the idea of letting the oData framework provide a querying mechanism on the exposed data objects and the fact that you can have a restful web service with some of the benefits of SOAP.
Service operations are only recognized if they are present on the class which derives from DataService. The WCF Data Service will not look into the context class for these. Also note that methods are not exposed by default, you need to attribute them with either WebGet or WebInvoke and allow access to them in your InitializeService implementation.
http://msdn.microsoft.com/en-us/library/cc668788.aspx