Skip to content
Advertisement

Why can’t Postman find my Spring REST API?

I created a very basic Spring Boot project with REST APIs. I tried connecting it to my Angular app but it was getting some CORS security error so I switched to Postman. I’m trying to test it using Postman but I keep receiving a 404 not found error on Postman. Why am I not able to connect to my backend and post to tester function?

controller

JavaScript

main

JavaScript

application.properties

JavaScript

pom.xml

JavaScript

console

JavaScript

equivalent cURL command

JavaScript

Postman

Postman request responding with 404

Advertisement

Answer

To fix the CORS issue, next to @PostMapping("/tester/{id}") add @CrossOrigin(origins = "http://localhost:<port>") where port is the port from which your Angular app is running.

In your target URL, make sure you’ve included the default Spring Boot port of 8080, e.g. http://localhost:8080/tester/123 and obviously, please double check that you’re doing a POST and not a GET.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement