Giter Club home page Giter Club logo

Comments (7)

carlosm27 avatar carlosm27 commented on July 17, 2024 1

This is new for me, sorry for not helping. But I'm glad you figure it out and share it here . I'm using a REST Client to make the requests. Also, I found another bug, once you have the server running and modify the database, and stop the server, it will show this
"Uncaught PermissionDenied: Acceso denegado. (os error 5), open './database.sqlite'
const rid = Deno.openSync(path, { read: true, write, create }).rid;"

I don't know why, but it "resolve" when the database.sqlite file is deleted.

from opine_api.

carlosm27 avatar carlosm27 commented on July 17, 2024

Hi,
Thanks for reporting this issue. I copy/paste the body you are trying to post and I got the same error. It worked when I write the body like this:
{
"departure": "Washington DC",
"destination": "Los Angeles",
"flightDuration": 5.5
}
The fields between "", and also I have specified the header as "application/json".

Please let me know if this worked for you.

from opine_api.

amundo avatar amundo commented on July 17, 2024

Thanks for the quick response.

Reformatting the body didn’t seem to make a difference, but adding the header changes something. This request:

fetch('http://localhost:3000/flight', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body: {
      departure: "Washington DC",
      destination: "Los Angeles",
      flightDuration: 5.5
    }
  })

…doesn’t cause a crash, but it doesn’t seem to add anything to the database either. I should be using POST as the HTTP verb to do that, no?

from opine_api.

amundo avatar amundo commented on July 17, 2024

FWIW I am getting a “Bad Request” in the response:

Response { 
  type: "basic", 
  url: "http://localhost:3000/flight", 
  redirected: false, 
  status: 400, 
  ok: false, 
  statusText: "Bad Request", 
  headers: Headers, 
  body: ReadableStream, 
  bodyUsed: false 
}

from opine_api.

amundo avatar amundo commented on July 17, 2024

I figured it out! This works. The body has to be JSON encoded:

fetch('http://localhost:3000/flight', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body: JSON.stringify({
      departure: "Washington DC",
      destination: "Los Angeles",
      flightDuration: 5.5
    })
  })
.then(response => console.log(response))

Thanks again!

from opine_api.

amundo avatar amundo commented on July 17, 2024

Hmm, must be something to do with how the sqlite db is being opened?

Are you running deno with --allow-read?

from opine_api.

carlosm27 avatar carlosm27 commented on July 17, 2024

Yes, deno run --allow-net --allow-write --allow-read app.ts

from opine_api.

Related Issues (2)

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.