Giter VIP home page Giter VIP logo

hands-on-full-stack-development-with-spring-boot-2.0-and-react's Introduction

Hands-On Full Stack Development with Spring Boot 2.0 and React

Hands-On Full Stack Development with Spring Boot 2.0 and React

This is the code repository for Hands-On Full Stack Development with Spring Boot 2.0 and React, published by Packt.

Build modern and scalable full stack applications using the Java-based Spring Framework 5.0 and React

What is this book about?

Apart from knowing how to write frontend and backend code, a full-stack engineer has to tackle all the problems that are encountered in the application development life cycle, starting from a simple idea to UI design, the technical design, and all the way to implementing, testing, production, deployment, and monitoring. This book covers the full set of technologies that you need to know to become a full-stack web developer with Spring Boot for the backend and React for the frontend.

This book covers the following exciting features:

  • Create a RESTful web service with Spring Boot
  • Understand how to use React for frontend programming
  • Gain knowledge of how to create unit tests using JUnit
  • Discover the techniques that go into securing the backend using Spring Security
  • Learn how to use Material UI in the user interface to make it more user-friendly

If you feel this book is for you, get your copy today!

https://www.packtpub.com/

Instructions and Navigations

All of the code is organized into folders. For example, Chapter03.

The code will look like the following:

@Entity
public class Car {
}

Following is what you need for this book: Java developers who are familiar with Spring, but have not yet built full-stack applications

With the following software and hardware list you can run all code files present in the book (Chapter 1-15).

Software and Hardware List

Chapter OS required Hardware required
1 Windows, Mac OS X, and Linux (Any) Common modern workstation
5 Windows, Mac OS X, and Linux (Any) Common modern workstation
14 Windows, Mac OS X, and Linux (Any) Common modern workstation

Related products

Get to Know the Author

Juha Hinkula is a software development lecturer at Haaga-Helia University of Applied Sciences in Finland. He received an MSc degree in computer science from the University of Helsinki. He has over 15 years of industry experience in software development. Over the past few years, he has focused on modern full stack development. He is also a passionate mobile developer with Android native technology and nowadays also uses React Native.

Suggestions and Feedback

Click here if you have any feedback or suggestions.

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781789138085

hands-on-full-stack-development-with-spring-boot-2.0-and-react's People

Contributors

abhishek1373 avatar akshadai avatar juhahinkula avatar packt-itservice avatar packtutkarshr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hands-on-full-stack-development-with-spring-boot-2.0-and-react's Issues

column name is desc

I stuck at this error for 30 minutes.

In chapter 2, when author talk about @column annotation, he give out the sample as below:
@Column(name="desc", nullable=false, length=512)
private String description

This code in fact dont include in the code base, just an example. However, when I add description to the Car model with the code above, it didnt work.

The reason is that 'desc' is a reserved keyword for MariaDB (among others). We need to change it to description (for example), by that the application can run.

Chapter 10 react-table is now react-table-6

Not your fault but react-table won't work, says you can't import so you do
npm i react-table-6
and change imports to
import ReactTable from 'react-table-6';
import 'react-table-6/react-table.css';

and it workss

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

I'm trying to run the RESTful service, however when I enter the url: http: // localhost: 8080 / cars; I get the following error: "SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data", noting in the raw data detail it shows me:

<html> <body> <h1> Whitelabel Error Page </ h1> <p> This application has not explicit mapping for / error, so you are seeing this as a fallback. </ p> <div id = 'created' > Wed Jul 18 00:09:49 COT 2018 </ div> <div> There was an unexpected error (type = Internal Server Error, status = 500). </ Div> <div> Type definition error: [simple type, class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList [0] - & gt; com.packt.cardatabase.domain.Car [& quot; owner & quot;] - & gt; com.packt. cardatabase.domain.Owner _ $$ _ jvstbe3_1 [& quot; handler & quot;]) </ div> </ body> </ html>

Please, could you help me find a solution?

Chapter 4 JWT MismatchedInputException: No content to map due to end-of-input

https://github.com/caverdude/java/blob/master/FullStackSpringBootReact-1-ch4-jwtauth.zip

I get something like this when accessing localhost:8080/login btw I am using H2 not MySQL that a problem? H2 worked fine with database auth which was where I started from when adding this JWT code. I may go back and try the MySQL later. I'm using Idea not Eclipse also.

com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
at [Source: (org.apache.catalina.connector.CoyoteInputStream); line: 1, column: 0]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4344) ~[ja

Chapter-04 code REST API issue

Hi,

I am trying to run Chapter-04 code to learn REST API using

 <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>

When I try : localhost:8080/api

It shows this error:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon Dec 10 20:14:29 PST 2018
There was an unexpected error (type=Forbidden, status=403).
Access Denied

Can you please fix the code or suggest how to go about this? The book is well written and I am enjoying it.

My environment is:

$ mvn -version
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T11:41:47-07:00)
Maven home: C:\mvn
Java version: 1.8.0_191-1-redhat, vendor: Oracle Corporation, runtime: C:\Java\jdk-1.8.0.191\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

The Spring Boot version: :: Spring Boot :: (v2.0.1.RELEASE)

logs.txt

chapter 3 page 64 can't get curl post to work

c:\dev\curl\bin>curl -X POST http://localhost:8080/api/cars -H "Content-Type: ap
plication/json" -d '{"brand": "Chevy","model": "G20 Van","color": "White","year"
: 1994,"price": 3000}'
{"cause":{"cause":null,"message":"Unexpected character (''' (code 39)): expected
a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'f
alse')\n at [Source: (org.apache.catalina.connector.CoyoteInputStream); line: 1,
column: 2]"},"message":"JSON parse error: Unexpected character (''' (code 39)):
expected a valid value (JSON String, Number, Array, Object or token 'null', 'tr
ue' or 'false'); nested exception is com.fasterxml.jackson.core.JsonParseExcepti
on: Unexpected character (''' (code 39)): expected a valid value (JSON String, N
umber, Array, Object or token 'null', 'true' or 'false')\n at [Source: (org.apac
he.catalina.connector.CoyoteInputStream); line: 1, column: 2]"}curl: (6) Could n
ot resolve host: Chevy,model
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: White,year
curl: (6) Could not resolve host: 1994,price
curl: (3) unmatched close brace/bracket in URL position 5:
3000}'
^

Postman post didn't work either.

{"cause":null,"message":"No suitable HttpMessageConverter found to read request body into object of type class com.packt.cardatabase.entity.Car from request with content type of text/plain;charset=UTF-8!"}

Security config

When you switch to JWT authorization you no need more to keep a cookie according to stateless principle of REST. You need to add some changes to SecurityConfig.java file like this
@OverRide
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().
csrf().disable().cors().and().authorizeRequests()
.antMatchers(HttpMethod.POST, "/login").permitAll()
.anyRequest().authenticated()
.and()
.addFilterBefore(new LoginFilter("/login", authenticationManager()),
UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(new AuthenticationFilter(),
UsernamePasswordAuthenticationFilter.class);
}

изображение

Chapter 4 Post to http://localhost:8080/login does not work

I am using the exact code on github chapter 4.

I am posting using postman to route
http://localhost:8080/login

With Body
{"user":"user", "password":"user"}

I tried to post both as JSON (application/json) and as Text. Both did not work.

Got the following response
{"timestamp":"2018-10-15T19:54:35.003+0000","status":403,"error":"Forbidden","message":"Access Denied","path":"/"}

com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input

hello,
i try visit http://localhost:8080/login, see the issue, then i try http://localhost:8080/api/login again, the web page display 403.
i runing Chapter04 code , see the issue. i don't know how to solve it,i hope you can help me.

code

SecurityConfig

@configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private UserDetailServiceImpl userDetailsService;

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
	auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
}

@Override
protected void configure(HttpSecurity http) throws Exception {
	http.csrf().disable().cors().and().authorizeRequests().antMatchers(HttpMethod.POST, "/login").permitAll()
			.anyRequest().authenticated().and()
			// Filter for the api/login requests
			.addFilterBefore(new LoginFilter("/login", authenticationManager()),
					UsernamePasswordAuthenticationFilter.class)
			// Filter for other requests to check JWT in header
			.addFilterBefore(new AuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
}

@Bean
CorsConfigurationSource corsConfigurationSource() {
	UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
	CorsConfiguration config = new CorsConfiguration();
	config.setAllowedOrigins(Arrays.asList("*"));
	config.setAllowedMethods(Arrays.asList("*"));
	config.setAllowedHeaders(Arrays.asList("*"));
	config.setAllowCredentials(true);
	config.applyPermitDefaultValues();
	source.registerCorsConfiguration("/**", config);
	return source;
}

LoginFilter

public class LoginFilter extends AbstractAuthenticationProcessingFilter {

public LoginFilter(String url, AuthenticationManager authManager) {
	super(new AntPathRequestMatcher(url));
	setAuthenticationManager(authManager);
}

@Override
public Authentication attemptAuthentication(HttpServletRequest req, HttpServletResponse res)
		throws AuthenticationException, IOException, ServletException {
	AccountCredentials creds = new ObjectMapper().readValue(req.getInputStream(), AccountCredentials.class);
	return getAuthenticationManager().authenticate(new UsernamePasswordAuthenticationToken(creds.getUsername(),
			creds.getPassword(), Collections.emptyList()));
}

@Override
protected void successfulAuthentication(HttpServletRequest req, HttpServletResponse res, FilterChain chain,
		Authentication auth) throws IOException, ServletException {
	AuthenticationService.addToken(res, auth.getName());
}

}
}

Ch04 - Login issues - MismatchedInputException: No content to map due to end-of-input

Hey

Getting an error for the Ch04 code when trying to login via the url /http://localhost:8080/login. This is happening in the code supplied on this site. For other URLs I get the white label 403 error page.

2018-07-23 21:45:58.306 ERROR 12553 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception

com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
at [Source: (org.apache.catalina.connector.CoyoteInputStream); line: 1, column: 0]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59) ~[jackson-databind-2.9.5.jar!/:2.9.5]
at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4133) ~[jackson-databind-2.9.5.jar!/:2.9.5]
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3988) ~[jackson-databind-2.9.5.jar!/:2.9.5]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3058) ~[jackson-databind-2.9.5.jar!/:2.9.5]
at com.packt.cardatabase.LoginFilter.attemptAuthentication(LoginFilter.java:34) ~[classes!/:0.0.1-SNAPSHOT]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:96) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178) ~[spring-security-web-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_171]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171]

Most CRUD Operations fail with jwt token

I am running into an issue with your code that makes the car PUT, POST from front end fail. My DELETE and GET requests do succeed though and I do believe I know why too.

Below is my code for POST and PUT request. Before turning jwt back on it was working perfectly.
`
addCar = (car) => {
const token = sessionStorage.getItem("jwt");

    axios.post(SERVER_URL + 'api/cars',
        {
            headers: {
                'Content-Type': 'application/json',
                'Authorization': token,
            },
            ...car
        })
        .then(res => this.fetchCars())
        .catch(err => console.error(err))
}

updateCar = (car, link) => {
const token = sessionStorage.getItem("jwt");

    axios.put(link,
        {
            headers: {
                'Authorization': token,
                'Content-Type': 'application/json',
            },
            ...car
        })
        .then(res =>
            this.setState({ open: true, message: 'Changes saved' })
        )
        .catch(err =>
            this.setState({ open: true, message: 'Error when saving' })
        );
}

`
I believe that PUT and POST are failing because the payload needs to be in the authorization. Part of jwt is to encrypt the payload with the token.

The reason why GET and DELETE request succeed though is that there is no payload to encrypt. So we just need to send the token with the request.

Can you please confirm.

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.