User service with caching, GET and POST
In order to implement a user profile, we must first implement a UserService
that can perform CRUD operations on IUser
. Before creating the service, you need to be running the lemon-mart-swagger-server
, so you can pull fake data with it while developing:
- Add a new script called
mock:standalone
topackage.json
package.json
"mock:standalone": "docker run -p 3000:3000 -t duluca/lemon-mart-swagger-server",
Note that this script presumes that you have independently built your swagger server on your local machine and/or published from a repository you can pull from.
- Execute the script
- Create a
baseUrl
property inenvironment.ts
andenvironment.prod.ts
with the url to your mock server
src/environments/environment.ts
export const environment = {
production: false,
baseUrl: 'http://localhost:3000'
}
- Create a
UserService
underuser/user
, as shown:
src/app/user/user/user.service.ts
@Injectable({
providedIn: 'root'
})
export class UserService extends CacheService...