-
Notifications
You must be signed in to change notification settings - Fork 0
Swagger API
Swagger is a specification and complete framework implementation for describing, producing, consuming, and visualizing RESTful web services. ServiceStack implements basic API in a separate plugin which is available under NuGet package: ServiceStack.Api.Swagger or StackExpress.Api.Swagger (unstable build).
Default configuration expects that ServiceStack services are available under '/api' path. If it's a brand new MVC project install NuGet Package: (http://nuget.org/packages/ServiceStack.Host.Mvc/) which prepares ServiceStack default services. Make sure that you added ignore for MVC routes:
routes.IgnoreRoute("api/{*pathInfo}");
If it's MVC4 project, then don't forget to disable WebAPI:
//WebApiConfig.Register(GlobalConfiguration.Configuration);
Enable Swagger plugin in AppHost.cs with:
public override void Configure(Container container)
{
...
Plugins.Add(new SwaggerFeature());
// uncomment CORS feature if it's has to be available from external sites
//Plugins.Add(new CorsFeature());
...
}
Compile it. Now you can access swagger UI with:
http://localost:port/swagger-ui/index.html
or
http://yoursite/swagger-ui/index.html
Each route could have a separate summary and description. You can set it with Route
attribute:
[Route("/hello", Summary = @"Default hello service.", Notes = "Longer description for hello service.")]
You can set specific description for each HTTP method like shown below:
[Route("/hello/{Name}", "GET", Summary = @"Says ""Hello"" to provided Name with GET.",
Notes = "Longer description of the GET method which says \"Hello\"")]
[Route("/hello/{Name}", "POST", Summary = @"Says ""Hello"" to provided Name with POST.",
Notes = "Longer description of the POST method which says \"Hello\"")]
Request DTO properties could be decorated with ApiMethod
attribute to specify what this attribute means.
[ApiMember(Name = "Name", Description = "Name Description", ParameterType = "path",
DataType = "string", IsRequired = true)]
public string Name { get; set; }
The complete list of available types could be find in Swagger documentation.
- Why ServiceStack?
- What is a message based web service?
- Advantages of message based web services
- Why remote services should use separate DTOs
- Getting Started
- Reference
- Clients
- Formats
- View Engines 4. Razor & Markdown Razor
- Hosts
- Advanced
- Configuration options
- Access HTTP specific features in services
- Logging
- Serialization/deserialization
- Request/response filters
- Filter attributes
- Concurrency Model
- Built-in caching options
- Built-in profiling
- Messaging and Redis
- Form Hijacking Prevention
- Auto-Mapping
- HTTP Utils
- Virtual File System
- Config API
- Physical Project Structure
- Modularizing Services
- Plugins
- Tests
- Other Languages
- Use Cases
- Performance
- How To
- Future