Giter Club home page Giter Club logo

Comments (3)

MarcinOrlowski avatar MarcinOrlowski commented on September 23, 2024

This is intentional and by design API must always return standardized JSON response, no matter what happened. That is the purpose of that ErrorHandler - to ensure this works that way, co slient app is not confused. There's no single benefit from breaking that rule. All it would make is whole things much worse to deal with. While you can easily alter the version you use I strongly suggest not doing so. This is just wrong.

from laravel-api-response-builder.

dragonfire1119 avatar dragonfire1119 commented on September 23, 2024

@MarcinOrlowski so your saying I need to split my api up & not have a site & api on the same install? It's still not user friendly for a customer to see a 404 json response when they're browsing the site? They should see a 404 blade view response.

from laravel-api-response-builder.

MarcinOrlowski avatar MarcinOrlowski commented on September 23, 2024

I am saying that your API should ALWAYS return JSON. This is what clients (programs, not humans!) consuming your API expect. There's absolutely no reason to return HTML from API. HTML error code 404 is also no exception from that. My ExceptionHandler will return standarized JSON, with success being false and closer details in message. This is perfectly sufficient for automated handling. Joe User does not need to be able to deal with it anyway as no user needs to call you API by hand and if s/he does so w/o knowledge what s/he is doing, then I'd just say it his problem.

And yes, separating API from main is a good thing. If both codes (API and website) share some code (i.e. models) you may create 3rd package with these elements and have them included in both projects via composer. Alternatively you need to modify the code to better handle 404, i.e. if request is for api/foo/bar and bar does not exists, then you need tor return JSON as this is api path, but if you face pages/bar and bar is non existing, then you need to return HTML 404. Lot of pointless work. Do the separation.

from laravel-api-response-builder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.