Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Protection of URLs: Front-end and Back-end

Premium
4:07

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

HV
Hitesh Varyani ✓ Link copied!

Hey povilas, I'm learning react with laravel in weekends, so first of all thanks for making it.

While developing a web app, I was stuck for sometime when I was using fetch, I was basically trying to send a post request using fetch but send me 302 and when used axios it give me expected result. I researched it on google but i didn't get that why it was happening. If you know that why this happend than please share me. For the ref. i'm sharing my code snippet. Thanks in advance.

return axios.post(API_PREFIX+'/api/v1/user/register', data, { headers: { 'Content-Type': 'application/json', } })

when this hit to server response was 422

but when i use below code it's sending me 302

fetch(API_PREFIX+'/api/v1/user/register', { method: 'POST', body: JSON.stringify(data), headers: { 'Content-Type': 'application/json', } })

PK
Povilas Korop ✓ Link copied!

Hi, not sure, 302 means that validation error treated it as a web request and redirected to the "previous page". So something is wrong with your headers. Try adding "Accept: application/json"

Maybe related article: Laravel: API Error Shows HTML and not JSON - How To Fix

HV
Hitesh Varyani ✓ Link copied!

Hey povilas, thanks for the response. This error is only occur when i use fetch, I'll try your suggestion thanks!!