Return a 304 HTTP response from within a REST API method?How to set HTTP Response Code in Custom REST APIHow to integrate magento REST API with third party?How to return a response from _create api rest methodNo response from POST to custom REST Api routeExtending REST API, route to custom methodHow to set HTTP Response Code in Custom REST APIMagento 2: Sending a Custom Header/Response from a ControllerREST API Update Product HTTP Method PUT or POST?Magento REST API Response is not return from _create() methodReturn Shipping Methods in Store REST APICustom REST API returns duplicate “response” tag

Export economy of Mars

Gold Battle KoTH

What is Modern Vipassana?

What printing process is this?

Need help with modelling a cylinder with a piece cut out?

Is law enforcement responsible for damages made by a search warrant?

Is it moral to remove/hide certain parts of a photo, as a photographer?

Why is the Vasa Museum in Stockholm so Popular?

Feedback diagram

Is it uncompelling to continue the story with lower stakes?

Basic CPA walkthrough

Is there a general term for the items in a directory?

How to transform a function from f[#1] to f[x]

Can an unintentional murderer leave Ir Miklat for Shalosh Regalim?

In a KP-K endgame, if the enemy king is in front of the pawn, is it always a draw?

Why does the friction act on the inward direction when a car makes a turn on a level road?

Why wasn't interlaced CRT scanning done back and forth?

How can I perform a deterministic physics simulation?

Does a bard know when a character uses their Bardic Inspiration?

A wiild aanimal, a cardinal direction, or a place by the water

How to call made-up data?

Is an "are" omitted in this sentence

Astable 555 circuit not oscillating

Who's behind community AMIs on Amazon EC2?



Return a 304 HTTP response from within a REST API method?


How to set HTTP Response Code in Custom REST APIHow to integrate magento REST API with third party?How to return a response from _create api rest methodNo response from POST to custom REST Api routeExtending REST API, route to custom methodHow to set HTTP Response Code in Custom REST APIMagento 2: Sending a Custom Header/Response from a ControllerREST API Update Product HTTP Method PUT or POST?Magento REST API Response is not return from _create() methodReturn Shipping Methods in Store REST APICustom REST API returns duplicate “response” tag






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















In a custom REST API endpoint method, returning the object promised in the service class interface will generate a 200 OK response. Additionally, I can return a specific HTTP error code by throwing an particular type of exception. For example, throwing a NoSuchEntityException returns a 404 NOT FOUND and a AuthorizationException returns a 401 UNAUTHORIZED.



My question: is there a way to return other HTTP codes, such as a 304 NOT MODIFIED code?










share|improve this question






























    0















    In a custom REST API endpoint method, returning the object promised in the service class interface will generate a 200 OK response. Additionally, I can return a specific HTTP error code by throwing an particular type of exception. For example, throwing a NoSuchEntityException returns a 404 NOT FOUND and a AuthorizationException returns a 401 UNAUTHORIZED.



    My question: is there a way to return other HTTP codes, such as a 304 NOT MODIFIED code?










    share|improve this question


























      0












      0








      0








      In a custom REST API endpoint method, returning the object promised in the service class interface will generate a 200 OK response. Additionally, I can return a specific HTTP error code by throwing an particular type of exception. For example, throwing a NoSuchEntityException returns a 404 NOT FOUND and a AuthorizationException returns a 401 UNAUTHORIZED.



      My question: is there a way to return other HTTP codes, such as a 304 NOT MODIFIED code?










      share|improve this question














      In a custom REST API endpoint method, returning the object promised in the service class interface will generate a 200 OK response. Additionally, I can return a specific HTTP error code by throwing an particular type of exception. For example, throwing a NoSuchEntityException returns a 404 NOT FOUND and a AuthorizationException returns a 401 UNAUTHORIZED.



      My question: is there a way to return other HTTP codes, such as a 304 NOT MODIFIED code?







      magento2 api rest






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 31 '16 at 20:16









      brendanmckeownbrendanmckeown

      806 bronze badges




      806 bronze badges























          2 Answers
          2






          active

          oldest

          votes


















          0














          Custom status codes are currently not supported, you can only get one of the following: 200, 400, 401, 403, 404, 406, 500 (see MagentoFrameworkWebapiException). If you have real use case when you need this functionality, feel free to create pull request or file an issue at https://github.com/magento/magento2 .






          share|improve this answer

























          • Hi @Alex Paliarush, Thanks for the answer. Just I want to know how we can send the above-mentioned error code from our custom rest api call(Post/Get)? Can you please show me the example?

            – Manish
            Mar 28 '17 at 5:46












          • Hi using this magento.stackexchange.com/questions/83852/…

            – Manish
            Mar 28 '17 at 6:21


















          1














          You can try send a custom http code in your service class using ResponseInterface.



          Here a little example:



          1. Define your service interface like this:

          <?php

          namespace TestModuleApi;

          interface TestApiInterface

          /**
          * @api
          *
          * @return MagentoFrameworkAppResponseInterface
          */
          public function foo();



          Now on your service class definition



          <?php

          namespace PaymentezModuleModel;

          use TestModuleApiTestApiInterface;
          use MagentoFrameworkApp
          RequestInterface,
          ResponseInterface
          ;

          class TestApi implements TestApiInterface

          /**
          * @var MagentoFrameworkAppRequestInterface
          */
          protected $request;

          /**
          * @var MagentoFrameworkAppResponseInterface
          */
          protected $response;

          /**
          * CustomerAddress constructor.
          * @param MagentoFrameworkAppRequestInterface $request
          * @param MagentoFrameworkAppResponseInterface $response
          */
          public function __construct(RequestInterface $request,
          ResponseInterface $response)

          $this->request = $request;
          $this->response = $response;


          /**
          * @api
          *
          * @return MagentoFrameworkAppResponseInterface
          */
          public function foo()

          $rawContent = $this->request->getContent();
          $params = json_decode($rawContent, true);

          $response = $this->response;
          $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
          $response->setContent(json_encode([
          'status' => false,
          'request_params' => $params
          ]));

          $response->send();

          // Ugly trick 😢 for force this response
          die;




          Now you can see the use of die sentence, but this trick prevent the next override of http status code and headers on the finally response






          share|improve this answer



























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f108871%2freturn-a-304-http-response-from-within-a-rest-api-method%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Custom status codes are currently not supported, you can only get one of the following: 200, 400, 401, 403, 404, 406, 500 (see MagentoFrameworkWebapiException). If you have real use case when you need this functionality, feel free to create pull request or file an issue at https://github.com/magento/magento2 .






            share|improve this answer

























            • Hi @Alex Paliarush, Thanks for the answer. Just I want to know how we can send the above-mentioned error code from our custom rest api call(Post/Get)? Can you please show me the example?

              – Manish
              Mar 28 '17 at 5:46












            • Hi using this magento.stackexchange.com/questions/83852/…

              – Manish
              Mar 28 '17 at 6:21















            0














            Custom status codes are currently not supported, you can only get one of the following: 200, 400, 401, 403, 404, 406, 500 (see MagentoFrameworkWebapiException). If you have real use case when you need this functionality, feel free to create pull request or file an issue at https://github.com/magento/magento2 .






            share|improve this answer

























            • Hi @Alex Paliarush, Thanks for the answer. Just I want to know how we can send the above-mentioned error code from our custom rest api call(Post/Get)? Can you please show me the example?

              – Manish
              Mar 28 '17 at 5:46












            • Hi using this magento.stackexchange.com/questions/83852/…

              – Manish
              Mar 28 '17 at 6:21













            0












            0








            0







            Custom status codes are currently not supported, you can only get one of the following: 200, 400, 401, 403, 404, 406, 500 (see MagentoFrameworkWebapiException). If you have real use case when you need this functionality, feel free to create pull request or file an issue at https://github.com/magento/magento2 .






            share|improve this answer













            Custom status codes are currently not supported, you can only get one of the following: 200, 400, 401, 403, 404, 406, 500 (see MagentoFrameworkWebapiException). If you have real use case when you need this functionality, feel free to create pull request or file an issue at https://github.com/magento/magento2 .







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 31 '16 at 22:43









            Alex PaliarushAlex Paliarush

            11.3k2 gold badges38 silver badges51 bronze badges




            11.3k2 gold badges38 silver badges51 bronze badges















            • Hi @Alex Paliarush, Thanks for the answer. Just I want to know how we can send the above-mentioned error code from our custom rest api call(Post/Get)? Can you please show me the example?

              – Manish
              Mar 28 '17 at 5:46












            • Hi using this magento.stackexchange.com/questions/83852/…

              – Manish
              Mar 28 '17 at 6:21

















            • Hi @Alex Paliarush, Thanks for the answer. Just I want to know how we can send the above-mentioned error code from our custom rest api call(Post/Get)? Can you please show me the example?

              – Manish
              Mar 28 '17 at 5:46












            • Hi using this magento.stackexchange.com/questions/83852/…

              – Manish
              Mar 28 '17 at 6:21
















            Hi @Alex Paliarush, Thanks for the answer. Just I want to know how we can send the above-mentioned error code from our custom rest api call(Post/Get)? Can you please show me the example?

            – Manish
            Mar 28 '17 at 5:46






            Hi @Alex Paliarush, Thanks for the answer. Just I want to know how we can send the above-mentioned error code from our custom rest api call(Post/Get)? Can you please show me the example?

            – Manish
            Mar 28 '17 at 5:46














            Hi using this magento.stackexchange.com/questions/83852/…

            – Manish
            Mar 28 '17 at 6:21





            Hi using this magento.stackexchange.com/questions/83852/…

            – Manish
            Mar 28 '17 at 6:21













            1














            You can try send a custom http code in your service class using ResponseInterface.



            Here a little example:



            1. Define your service interface like this:

            <?php

            namespace TestModuleApi;

            interface TestApiInterface

            /**
            * @api
            *
            * @return MagentoFrameworkAppResponseInterface
            */
            public function foo();



            Now on your service class definition



            <?php

            namespace PaymentezModuleModel;

            use TestModuleApiTestApiInterface;
            use MagentoFrameworkApp
            RequestInterface,
            ResponseInterface
            ;

            class TestApi implements TestApiInterface

            /**
            * @var MagentoFrameworkAppRequestInterface
            */
            protected $request;

            /**
            * @var MagentoFrameworkAppResponseInterface
            */
            protected $response;

            /**
            * CustomerAddress constructor.
            * @param MagentoFrameworkAppRequestInterface $request
            * @param MagentoFrameworkAppResponseInterface $response
            */
            public function __construct(RequestInterface $request,
            ResponseInterface $response)

            $this->request = $request;
            $this->response = $response;


            /**
            * @api
            *
            * @return MagentoFrameworkAppResponseInterface
            */
            public function foo()

            $rawContent = $this->request->getContent();
            $params = json_decode($rawContent, true);

            $response = $this->response;
            $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
            $response->setContent(json_encode([
            'status' => false,
            'request_params' => $params
            ]));

            $response->send();

            // Ugly trick 😢 for force this response
            die;




            Now you can see the use of die sentence, but this trick prevent the next override of http status code and headers on the finally response






            share|improve this answer





























              1














              You can try send a custom http code in your service class using ResponseInterface.



              Here a little example:



              1. Define your service interface like this:

              <?php

              namespace TestModuleApi;

              interface TestApiInterface

              /**
              * @api
              *
              * @return MagentoFrameworkAppResponseInterface
              */
              public function foo();



              Now on your service class definition



              <?php

              namespace PaymentezModuleModel;

              use TestModuleApiTestApiInterface;
              use MagentoFrameworkApp
              RequestInterface,
              ResponseInterface
              ;

              class TestApi implements TestApiInterface

              /**
              * @var MagentoFrameworkAppRequestInterface
              */
              protected $request;

              /**
              * @var MagentoFrameworkAppResponseInterface
              */
              protected $response;

              /**
              * CustomerAddress constructor.
              * @param MagentoFrameworkAppRequestInterface $request
              * @param MagentoFrameworkAppResponseInterface $response
              */
              public function __construct(RequestInterface $request,
              ResponseInterface $response)

              $this->request = $request;
              $this->response = $response;


              /**
              * @api
              *
              * @return MagentoFrameworkAppResponseInterface
              */
              public function foo()

              $rawContent = $this->request->getContent();
              $params = json_decode($rawContent, true);

              $response = $this->response;
              $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
              $response->setContent(json_encode([
              'status' => false,
              'request_params' => $params
              ]));

              $response->send();

              // Ugly trick 😢 for force this response
              die;




              Now you can see the use of die sentence, but this trick prevent the next override of http status code and headers on the finally response






              share|improve this answer



























                1












                1








                1







                You can try send a custom http code in your service class using ResponseInterface.



                Here a little example:



                1. Define your service interface like this:

                <?php

                namespace TestModuleApi;

                interface TestApiInterface

                /**
                * @api
                *
                * @return MagentoFrameworkAppResponseInterface
                */
                public function foo();



                Now on your service class definition



                <?php

                namespace PaymentezModuleModel;

                use TestModuleApiTestApiInterface;
                use MagentoFrameworkApp
                RequestInterface,
                ResponseInterface
                ;

                class TestApi implements TestApiInterface

                /**
                * @var MagentoFrameworkAppRequestInterface
                */
                protected $request;

                /**
                * @var MagentoFrameworkAppResponseInterface
                */
                protected $response;

                /**
                * CustomerAddress constructor.
                * @param MagentoFrameworkAppRequestInterface $request
                * @param MagentoFrameworkAppResponseInterface $response
                */
                public function __construct(RequestInterface $request,
                ResponseInterface $response)

                $this->request = $request;
                $this->response = $response;


                /**
                * @api
                *
                * @return MagentoFrameworkAppResponseInterface
                */
                public function foo()

                $rawContent = $this->request->getContent();
                $params = json_decode($rawContent, true);

                $response = $this->response;
                $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
                $response->setContent(json_encode([
                'status' => false,
                'request_params' => $params
                ]));

                $response->send();

                // Ugly trick 😢 for force this response
                die;




                Now you can see the use of die sentence, but this trick prevent the next override of http status code and headers on the finally response






                share|improve this answer













                You can try send a custom http code in your service class using ResponseInterface.



                Here a little example:



                1. Define your service interface like this:

                <?php

                namespace TestModuleApi;

                interface TestApiInterface

                /**
                * @api
                *
                * @return MagentoFrameworkAppResponseInterface
                */
                public function foo();



                Now on your service class definition



                <?php

                namespace PaymentezModuleModel;

                use TestModuleApiTestApiInterface;
                use MagentoFrameworkApp
                RequestInterface,
                ResponseInterface
                ;

                class TestApi implements TestApiInterface

                /**
                * @var MagentoFrameworkAppRequestInterface
                */
                protected $request;

                /**
                * @var MagentoFrameworkAppResponseInterface
                */
                protected $response;

                /**
                * CustomerAddress constructor.
                * @param MagentoFrameworkAppRequestInterface $request
                * @param MagentoFrameworkAppResponseInterface $response
                */
                public function __construct(RequestInterface $request,
                ResponseInterface $response)

                $this->request = $request;
                $this->response = $response;


                /**
                * @api
                *
                * @return MagentoFrameworkAppResponseInterface
                */
                public function foo()

                $rawContent = $this->request->getContent();
                $params = json_decode($rawContent, true);

                $response = $this->response;
                $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
                $response->setContent(json_encode([
                'status' => false,
                'request_params' => $params
                ]));

                $response->send();

                // Ugly trick 😢 for force this response
                die;




                Now you can see the use of die sentence, but this trick prevent the next override of http status code and headers on the finally response







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 24 at 22:05









                SairokoSairoko

                111 bronze badge




                111 bronze badge






























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f108871%2freturn-a-304-http-response-from-within-a-rest-api-method%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

                    Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

                    Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림