Agent skill
angular-json-server-setup
Add, repair, or verify a local json-server mock REST API for Angular 20 workspaces, including deterministic dependency setup, `mocks/db.json`, proxy wiring (`src/proxy.conf.json` + `angular.json`), npm scripts, and mock API docs. Use when users ask to create/fix `/api` proxy flows, run Angular+API together, troubleshoot json-server option/version mismatches, or add advanced middleware/routes/auth simulation.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/angular-json-server-setup
SKILL.md
Angular 20 json-server Setup
Goal
Provide a repeatable, repo-friendly setup for a local mock REST API using json-server, integrated with Angular 20 development (ng serve, proxy, scripts, and a sane folder layout).
Recommended Layout
Create this structure at repo root:
/
mocks/
db.json
README.md
src/
proxy.conf.json
package.json
angular.json
Inputs
projectRoot(string, default: current working directory)apiPort(number, default:3000)apiPrefix(string, default:/api)useConcurrently(boolean, default:true)addAdvancedServerTemplate(boolean, default:false)packageManager(string, default: auto-detect from lockfile:npm|pnpm|yarn)
Success Criteria
json-serveris installed as a dev dependency.mocks/db.jsonexists and serves resources.src/proxy.conf.jsonexists and rewrites/api/*to the mock API origin.angular.jsonserve options includeproxyConfig: "src/proxy.conf.json".npm run start:mockstarts Angular and mock API together.- Angular uses relative
/api/...calls instead of hardcodedlocalhostURLs.
Workflow
-
Preflight and workspace validation
- Resolve
projectRootto an absolute path. - Detect package manager from lockfile:
pnpm-lock.yaml->pnpmyarn.lock->yarn- otherwise ->
npm - Confirm
angular.jsonandpackage.jsonexist inprojectRoot. - Confirm
@angular/coremajor version is20. - Abort with an error when the project is not Angular 20.
- If monorepo/multi-project, apply proxy and serve updates to the actively used Angular app target; do not modify unrelated targets.
- Resolve
-
Install dependencies
- Install
json-serveras a dev dependency using detected package manager:
bashnpm i -D json-server- If
useConcurrentlyis true, installconcurrentlyas a dev dependency:
bashnpm i -D concurrently- Keep installs local; do not require global packages.
- Do not downgrade or remove unrelated dependency entries.
- Install
-
Create
mocks/db.json- Ensure
mocks/exists. - Create
mocks/db.jsonwith valid JSON when missing. - If it already exists, preserve existing data.
- Prefer this minimal seed when no domain data is provided:
json{} - Ensure
-
Add npm scripts in
package.json- Ensure these scripts exist (merge safely with existing scripts):
json{ "scripts": { "mock:api": "json-server ./mocks/db.json --port 3000", "start": "ng serve", "start:mock": "concurrently -n API,NG \"npm:mock:api\" \"npm:start\"" } }- If
useConcurrentlyis false, setstart:mockto only run the API script:
json{ "scripts": { "start:mock": "npm run mock:api" } }- Preserve script names unless the user asks otherwise.
- Update scripts idempotently:
- create missing keys
- replace only targeted script values
- never remove unrelated scripts
-
Configure Angular proxy
- Create or update
src/proxy.conf.json:
json{ "/api": { "target": "http://localhost:3000", "secure": false, "changeOrigin": true, "logLevel": "debug", "pathRewrite": { "^/api": "" } } }- If
apiPrefixdiffers from/api, update both the top-level key andpathRewriteconsistently. - In
angular.json, setproxyConfigunder the active serve target: - preferred path:
projects.<name>.architect.serve.options.proxyConfig - alternate path in newer builders:
projects.<name>.targets.serve.options.proxyConfig - Do not delete existing serve options when inserting
proxyConfig.
json{ "proxyConfig": "src/proxy.conf.json" } - Create or update
-
Apply Angular usage pattern
- Prefer environment-based API base URL in development.
- Set
apiBaseUrl: '/api'inenvironment.development.ts. - Build service URLs as
${environment.apiBaseUrl}/resource. - Do not hardcode
http://localhost:3000in app code.
-
Add mock API docs
- Create
mocks/README.mdwith: - endpoint list
- run commands (
npm run mock:api,npm run start:mock) - sample curl commands
- reset instructions (edit or replace
mocks/db.json) - Include one troubleshooting section for common errors:
Unknown optionfromjson-server- proxy not applied due to wrong serve target
- hardcoded backend URLs bypassing
/api
- Create
-
Verify setup
- Run:
bashnpm run start:mock- Verify process behavior:
- API listens on
apiPort - Angular serve starts successfully
- Verify integration behavior:
- Angular app can call
${apiPrefix}/...without CORS errors - resources in
mocks/db.jsonmap to endpoints - proxy rewrite removes
apiPrefixbefore reaching json-server - Verify code hygiene:
- no hardcoded
http://localhost:<apiPort>in Angular data services - if found, convert calls to relative
${apiPrefix}base URLs
Advanced Rules (Version-Sensitive)
-
Handle v1 differences explicitly
- Recent
json-serverversions in the v1 beta line differ from v0.17. - Expect changes including:
- ID handling differences (string-like IDs in many scenarios)
- pagination via
_page+_per_page - removed delay flag behavior
- Recent
-
Avoid relying on removed/changed CLI flags
- Do not assume
--delayworks in newer versions. - Do not assume
--routesand--middlewaresflags are available across versions. - If users report
Unknown option, treat it as version/line mismatch first.
- Do not assume
-
Prefer module-based wrapper for advanced behavior
- For auth simulation, custom routes, custom middleware, artificial latency, or reset endpoints:
- create a small Node wrapper (
server.jsormocks/server.js) usingjson-serveras a module - attach custom middleware and route handlers before delegating to the router
- keep this optional and enabled only when requested
Guardrails
- Merge JSON changes safely; do not overwrite unrelated config.
- Keep edits idempotent; running this skill multiple times should converge to the same working state.
- Keep API URLs in Angular app relative (
/api/...). - Keep
mocks/db.jsoncommitted for reproducibility. - Prefer small, explicit defaults over broad scaffolding.
- If conflicting existing conventions are present, preserve them unless they break success criteria.
Assistant Portability Rules
- Drive edits from on-disk config and lockfiles; do not assume a package manager or Angular target without checking.
- Keep script/proxy mutations idempotent and narrowly scoped to required keys.
- If active serve target resolution is ambiguous, stop with one explicit blocker and required target path.
Definition of Done
npm run start:mocklaunches Angular + mock API.- Angular calls to
/api/...succeed through proxy without CORS issues. - Endpoints are generated from
mocks/db.json. - Mock API run/reset/extension steps are documented in
mocks/README.md. - Re-running setup does not corrupt scripts or Angular serve configuration.
References
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?