Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Vahid Panjganj
    any one there ?
    Jourdan Rodrigues
    @vpanjganj I'm not quite familiar with json-server, but I can try to help.
    Vahid Panjganj

    my app is making ajax calls against an api. I’m using axios to make my requests. The api sends the pagination info via headers.
    and axios has a header property in its response. however , I don’t see any of the headers I want inside my code, even I logged the whole response object and my header keys weren’t there. Surprisingly when I check the response in my chrome dev too network tab. The pagination stuff are there. 

this is header I get in my code

x-total-count: "500", 
    pragma: "no-cache", 
    content-type: "application/json; 
    cache-control: "no-cache", 
    expires: "-1"


this is what I get in chrome dev tool

    Access-Control-Expose-Headers:X-Total-Count, Links
    Content-Type:application/json; charset=utf-8
    Date:Wed, 02 Nov 2016 15:10:57 GMT
    Link:<http://localhost:3001/articles?_sort=lastHourViews&_order=ASC&_page=1>; rel="first", <http://localhost:3001/articles?_sort=lastHourViews&_order=ASC&_page=2>; rel="next", <http://localhost:3001/articles?_sort=lastHourViews&_order=ASC&_page=50>; rel="last"
    Vary:Origin, Accept-Encoding
    Vahid Panjganj
    no not fixed
    I submitted an issue :/
    Kenneth Solberg
    anyone else having problems posting to nested resource (f.ex. /posts/1/comments) ? ... i keep getting 404
    Michele Gatti
    Is possible to configurate json-server with a docker container?
    is it possible to this project work with sqlite database not in json file
    Marcus Kovács
    I'm strugling to figure out if there is a way in a server.get() function to look at data within the watched json database file ?
    I thought, maybe use the router object but I cant find a way to access the data. I like to validate something in a server.post('/someurl'...) before I send the response
    Arye Shalev
    Love this server!
    question related to lowdb, how can i use chained functions with iterating such as map/foreach/mapValues etc, it seems it can't be since it s a collection.
    i have this issue because i have nested objects and arrays.
    Arye Shalev

    for example i have this json

        shelveId: 0,
        books: [{...},{...},{...}]
        shelvId: 1,
        books: [{...},{...}]

    i would like to get a json as {shelveId, numBooks} so in our case:

      "0":  3,
      "1": 2

    how can i acheive that with the server using the lowdb functions and lodash i tried but no example of foreach or map, thanks!

    Tameshwar Nirmalkar
    how to achieve pagination in custom routes in json-server

    "/test/:start/:end": "/pagination?_start=:start&_end=:end"

    this doesn't work

    can anybody help me on this
    Tameshwar Nirmalkar
    "/test/:start/:end": "/list?_start=:start&_end=:end"
    Hey guys, what does --watch do?
    Hi everyone. I am using json-server to do a version of a portal in standalone. The portal does a request with a pdf response. Does anyone know how to give a pdf in response ? I have the pdf in local folder
    Jon Duffy
    @thijskoek pass a json file to --watch and json sever will serve it
    I can't quite work out how to do deeper routes . for example /rockets/launches/{1}
    Jon Duffy
    or maybe, how to serve nested data
    would be a better description
    One more question. I have a db.json and a routes.json : routes.json reference all routes of my json-server but I have an error when i start my json-server : Range out of order in character class at Regexp (native). My route is this : "/myroutes/reports[001]"
    I know that this character "[" and this "]" caused the error but i can't remove this characters rom the request
    Can anyone help me please ?
    Hi how can i make it possible to access /text/get for example?
    json server Oops, found / character in database property can i make a / work?
    Victor Guilherme Santos Hogemann
    hi folks, how can I access the db from a custom route? Or this is only possible from the router.render() method?
    Arye Shalev
    Hi guys, i love this json-server it saved my life! i wonder if anyone here found a semi automated solution like this with real DB? that create auto routes for _embed and _expand by a structure of you JSON file with real DB such as Mongo or Sqlite? thanks!
    André Drougge
    Hi all
    Great mock server, working great for me developing my front-end while the API guys are too slow.
    I want to specify a response from the server, when I do a POST. I have a middleware but I can’t really see where I can change the response body in the res.
    André Drougge
    I see there’s an idea about authentication in the docs, however I still have the same issue.
    in my isAuthenticated(req) method, I want to check if the request had a certain header (auth token). I keep doing console.log(req) to see where I can find the headers I send.. but to no avail - I can not for the life in me find headers in the request.
    req.headers doesn’t show the token that I do send in my req, actually those headers are all different from the ones I send.
    André Drougge
    Don’t really want to mention, but I think this is such a simple thing if you know how to reach it - @typicode perhaps you can shed some light on this.
    André Drougge
    André Drougge
    Perhaps @hlobil or @imikay ?
    Arye Shalev
    @miphe you answered yourself(!)
    req.headers is the object of the headers sent from the client
    const isAuthorized = (req) => {
      return req.headers['AUTH_TOKEN'] ? true : false;
    in your question you pasted the request headers of your client and it DOESNT send 'auth_token`
    just add it to your request headers of any AJAX lib you are using
    Jafeth Díaz
    Hi, how would I set custom ids for different resources?
    Hi guys,
    does anybody know how to add simple headers to a specifgied request?

    I have a nice solution using --middleware ;)

    "startAPI": "json-server --watch server/mockedBackendAPI.json --routes server/mockedBackendRoutes.json --port 3004 --middlewares server/middleware.js"

    module.exports = (req, res, next) => { res.header('X-Hello', 'World') next() }