Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8608313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:34:48+00:00 2026-06-12T03:34:48+00:00

Environment is Visual Studio 2012, ServiceStack, ASP.NET Web Application Project (followed https://github.com/ServiceStack/ServiceStack/wiki/Create-your-first-webservice ) Looking

  • 0

Environment is Visual Studio 2012, ServiceStack, ASP.NET Web Application Project (followed https://github.com/ServiceStack/ServiceStack/wiki/Create-your-first-webservice)

Looking through some of the classes in ServiceStack.Examples, I noticed that most of the services contain only one method. Either some override on Execute() or, if a REST service, some override of OnPost/Get/Put/Delete().

How should I approach making a full API set, if I have tens of functions I need implemented RegisterUser(), RemoveUser(), AddFriend(), RemoveFriend() … One service per method?

public RegisterUserService : IService<User> { public object Execute(User> dto) { ... } }
public RemoveUserService : IService<User> { public object Execute(User> dto) { ... } }
public AddFriendService : IService<Friend> { public object Execute(Friend dto) { ... } }
public RemoveFriendService: IService<RequestDTO4> { public object Execute(Friend dto) { ... } }

I’m pretty lost on how to begin implementing a full API set. I’ve read the first and second wiki page on ‘Creating your first webservice’, which I’ve copied to make 1 service method. But now I want to make 10 or 40 service methods and I’m not sure how to do that.

I noticed that implementing from IRestService<T> allows you up to 4 methods instead of the one Execute() method, simply because each method corresponds to a different HTTP verb. So is there something like that I could write? Basically something like:

public MyService : IService/IRestService/ServiceBase?<User>
{
     public object AddUser(User user) { }
     public object RemoveUser(User user) { }
     public object ModifyUser(User user) { }
}

Just looking for something that doesn’t necessarily have to contain all methods in one service class, but as many as reasonably possible … do I really have to create 1 service for each service method?

Note on pursuing a strictly RESTful architecture: I only read up a little on REST, but it seems like I’d have to strictly follow rules like: treat everything as a resource even if you have to re-design your models, no verbs in the URL names (/Friends, not /GetFriends because REST gives you OnGet(), OnPost(), OnPut(), and OnDelete() … basically I’m interested in the easiest, quickest, and most painless way of implementing a a few dozen service methods. It’s a personal project, so the requirements won’t vary too much.

Thanks in advance for guiding me through this first step.

EDIT: Just saw this related question: How to send commands using ServiceStack?

Mythz said there’s no “ServiceStack way” to design. The guy’s question is pretty much like mine. I’m wondering how to stack a lot of service methods in a service.

EDIT 2: Just saw Need help on servicestack implementation, and Separate or combined ServiceStack services?.

I just tested the code below successfully with working routes:

[Route("/registerUser/setEmail/{Email}")]
[Route("/registerUser/setPassword/{Password}")]
[Route("/registerUser/setPhoneNumber/{PhoneNumber}")]
[Route("/lalal2395823")]
[Route("/test3234/test23423511")]
public class RegisterUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Nickname { get; set; }
    public string PhoneNumber { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
}

But what I’d like is for each [Route("path")] to go to a different method, instead of having them all parsed in Execute() and having to parse which string isn’t null or empty.


My Solution

I decided to take Rickard’s advice and make a proper REST API, because it seems simpler and cleaner in the end.

This is now my class using the new ServiceStack API (new as of 9/24/12):

using UserModel = Project.Model.Entities.User;

[Route("/User", "POST")]
[Route("/User/{FirstName}", "POST")]
[Route("/User/{FirstName}/{LastName}", "POST")]
[Route("/User/{FirstName}/{LastName}/{Nickname}", "POST")]
[Route("/User/{FirstName}/{LastName}/{Nickname}/{PhoneNumber}", "POST")]
[Route("/User/{FirstName}/{LastName}/{Nickname}/{PhoneNumber}/{Email}", "POST")]
public class CreateUser : IReturn<UserModel>
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Nickname { get; set; }
    public string PhoneNumber { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
}

public class CreateUserService : Service
{
   public object Post(CreateUser request)
    {
        try
        {
            using (var session = FluentNHibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var user = new UserModel()
                    {
                        FirstName = request.FirstName,
                        LastName = request.LastName,
                        Nickname = request.Nickname,
                        PhoneNumber = request.PhoneNumber,
                        Email = request.Email,
                        Password = request.Password,
                    };
                    session.SaveOrUpdate(user);
                    transaction.Commit();

                    return user;
                }
            }
        }
        catch
        {
            throw;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:34:50+00:00Added an answer on June 12, 2026 at 3:34 am

    Following the HTTP way you have to turn your way of thinking upside down. You need to think in terms of resources, i.e. users, friends, etc. Using HTTP you already have a finite set of methods, namely Get, Put, Post, and Delete.

    Hence, the service API design could look like this:

    RegisterUser() => POST /users
    RemoveUser() => DELETE /users/{userid}
    AddFriend() => POST /users/{userid}/friends
    RemoveFriend() => DELETE /users/{userid}/friends/{friendid}
    ModifyUser() => PUT /users/{userid}
    

    etc.

    To implement for example RemoveFriend in ServiceStack you could do like this:

    public class UserFriendService : RestServiceBase<UserFriendRequest>
    {
        public override object OnPost(UserFriendRequest request)
        {
            // pseudo code 
            var user = GetUser(request.UserId);
            var friend = GetUser(request.FriendId); // FriendId is a field in the HTTP body
            user.Friends.Add(friend);
            return HttpResult.Status201Created(user, ...);
        }
        //...
    }
    
    [Route("/users/{userId}/friends")]
    public class UserFriendRequest
    {
        public string UserId { get; set; }
        public string FriendId { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Environment Visual Studio 2008 SP1 Visual C# WPF Application Project .NET Framework 3.5 Problem
Environment: Visual Studio Ultimate 2010 Windows XP WPF Desktop Application using .NET 4.0 We
How do I set Environment Variables in Visual Studio 2010? I found this web
Our environment: Visual Studio 2010, c#, .net 4 client profile. We have a Winforms
I need to be able to target .NET Framework 4.0 using Visual Studio 2012
Enviroment: Visual Studio 2012, MVC4, Razor, Internet Application. I have a code with search
Enviroment: Visual Studio 2012, MVC4, Razor, Internet Application. I have a JavaScript array.. var
I'm using Visual Studio 2010 and VB.NET . My target environment is .NET Framework
Environment: Visual Studio Ultimate 2010 .NET 4.0 Windows XP, Vista and 7 We have
Enviroment: Visual Studio 2012, MVC4, Razor, Internet Application. I'm working with eBay API and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.