Skip to content

Todo example getting 404 error #1090

@vijeta-singh

Description

@vijeta-singh

Hi Everyone,

I am trying to learn loopback 4 so I have started with the to-do example.
https://github.com/strongloop/loopback-next/tree/master/packages/example-getting-started

I have removed all api call , i have just get and post.
Get is working fine but on post request I am getting 404 error.
OPTIONS http://localhost:3000/todo 404 (Not Found)
Failed to load http://localhost:3000/todo: Response for preflight has invalid HTTP status code 404.

import {get, post, param} from '@loopback/rest';
import {HttpErrors} from '@loopback/rest';
import {TodoSchema, Todo} from '../models';

import {inject} from '@loopback/core';
import {repository} from '@loopback/repository';
import {TodoRepository} from '../repositories/index';

export class TodoController {
    repository: TodoRepository;

    constructor() {
        this.repository = new TodoRepository();
    }

    @get('/hello')
    hello(): string {
      return 'Hello world!';
    }


    @get('/todo')
  async findTodos(): Promise<Todo[]> {
    return await this.repository.find();
  }

  @post('/todo')
  async createTodo(
    @param.body('todo', TodoSchema)
    todo: Todo,
  ) {
      console.log('inside post');
    // TODO(bajtos) This should be handled by the framework
    // See https://github.com/strongloop/loopback-next/issues/118
    if (!todo.title) {
      return Promise.reject(new HttpErrors.BadRequest('title is required'));
    }
    console.log('after if');
    return await this.repository.create(todo);
  }

  }

Please let me know how I can fix this issue.

Thanks

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions