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 8700895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:16:27+00:00 2026-06-13T02:16:27+00:00

I’ve an entity with an ID of public string ID {get;set;} activities/1 (which comes

  • 0

I’ve an entity with an ID of

public string ID {get;set;}    
activities/1

(which comes from RavenDB).

I’m registering the following routes in my ServiceStack AppHost

Routes
    .Add<Activity>("/activities")
    .Add<Activity("/activities/{id}");

I’m using a backbone app to POST and PUT to my REST Service.

What happens out-of-the-box:

  • id property is serialized into the json as “activities/1”
  • id property is encoded into route as “activities%2F1”
  • ServiceStack gives precedence to the URL based id property, so my string gets the encoded value which is no use to RavenDb directly.

The options I’m aware of:

  • Change backbone to post to “/activities” and let the JSON Serialiser kick in
  • Change RavenDb ID generation to use hyphens rather than slashes
  • Make my Id property parse for the encoded %2F on set and convert to a slash

Both have disadvantages in that I either lose RESTfulness in my API, which is undesirable, or I don’t follow RavenDb conventions, which are usually sensible out-of-the-fox. Also, I’ve a personal preference for having slashes.

So I’m wondering if there are any other options in servicestack that I could use to sort this issue that involve less compromise? Either Serialiser customisation or wildcard routing are in my head….

  • 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-13T02:16:28+00:00Added an answer on June 13, 2026 at 2:16 am

    I have the same problem with ASP.Net WebAPI, so I don’t think this is so much a ServiceStack issue, but just a general concern with dealing with Raven style id’s on a REST URL.

    For example, let’s say I query GET: /api/users and return a result like:

    [{
      Id:"users/1",
      Name:"John"
    },
    {
      Id:"users/2",
      Name:"Mary"
    }]
    

    Now I want to get a specific user. If I follow pure REST approach, the Id would be gathered from this document, and then I would pass it in the id part of the url. The problem here is that this ends up looking like GET: /api/users/users/1 which is not just confusing, but the slash gets in the way of how WebAPI (and ServiceStack) route url parameters to action methods.

    The compromise I made was to treat the id as an integer from the URL’s perspective only. So the client calls GET: /api/users/1, and I define my method as public User Get(int id).

    The cool part is that Raven’s session.Load(id) has overloads that take either the full string form, or the integer form, so you don’t have to translate most of the time.

    If you DO find yourself needing to translate the id, you can use this extension method:

    public static string GetStringIdFor<T>(this IDocumentSession session, int id)
    {
      var c = session.Advanced.DocumentStore.Conventions;
      return c.FindFullDocumentKeyFromNonStringIdentifier(id, typeof (T), false);
    }
    

    Calling it is simple as session.GetStringIdFor<User>(id). I usually only have to translate manually if I’m doing something with the id other than immediately loading a document.

    I understand that by translating the ids like this, that I’m breaking some REST purist conventions, but I think this is reasonable given the circumstances. I’d be interested in any alternative approaches anyone comes up with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace

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.