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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:38:56+00:00 2026-06-03T01:38:56+00:00

I would like to set ServiceStack’s default format to JSON, as opposed to the

  • 0

I would like to set ServiceStack’s default format to JSON, as opposed to the HTML formatted response it normally returns when a service is accessed from a browser. I know this can be specified on each request by sending a ?format=json parameter or setting the Accept header to application/json. Is there a way to change this without having to rely on these hints from the request?

  • 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-03T01:38:57+00:00Added an answer on June 3, 2026 at 1:38 am

    In addition to specifying it on the QueryString with ?format=json, by appending the format .ext to the end of the route, e.g: /rockstars.json, or by specifying the HTTP Header (in your HttpClient): Accept: application/json.

    Otherwise if your HttpClient doesn’t send an Accept header you can specify JSON as the default content type in your AppHost with:

    SetConfig(new HostConfig {
         DefaultContentType = MimeTypes.Json 
    });
    

    All Configuration options in ServiceStack are set here.

    The issue when calling web services from a web browser is that they typically ask for Accept: text/html and not JSON which by contract ServiceStack obliges by returning back HTML if it is enabled.

    To ensure JSON is returned you may also want to disable the HTML feature with:

    SetConfig(new HostConfig {
        EnableFeatures = Feature.All.Remove(Feature.Html),
    });
    

    Different ways to specify the Response Content Type

    Otherwise if you want to override the Accept header you can force your service to always return json with any of these ways to Customize the HTTP Response, e.g:

    Using a filter (AddHeader is built-in):

    [AddHeader(ContentType=MimeTypes.Json)]
    public object Any(Request request) { ... }
    

    Setting the Response in the service:

    public object Any(Request request) 
    { 
        base.Response.ContentType = MimeTypes.Json;
        return dto;
    }
    

    Returning a decorated response:

    return new HttpResult(dto, MimeTypes.Json);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to set the new child documents to default to a set
i would like to set the date format of all the dates in my
I would like to set up a project to be published as HTML using
I would like set a default value for a date picker field in a
I would like to set some initial variables (like format compact and the current
Hi I would like set default value for binding on Text property. In widows
I would like to set up on my server a service that would determine
I would like to set the default number of displayed rows in the admin
I used the same command syntax above as in Mysql and would like set
I would like to set some limits/boundaries on the amount of pixels we can

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.