Group Group Group Group Group Group Group Group Group

Ktor: REST API for Mobile | raywenderlich.com

In this tutorial, you’ll create a REST API server for mobile apps using the new Ktor framework from JetBrains.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/7265034-ktor-rest-api-for-mobile

Hello. Amazing tutorial. This is like the best content available on the whole on Internet about ‘Ktor’ I guess. But, I have found a small issue while I was setting up the environment variables after copying it from the article.

JDBC_DRIVER=org.postgresql.Driver
JDBC_DATABASE_URL=jdbc:postgresql:todos?user=postgres;
SECRET_KEY=898748674728934843
JWT_SECRET=898748674728934843

The JDBC_DATABASE_URL is set as, jdbc:postgresql:todos?user=postgres; As you can see the user is set as “postgres;” with an extra semi colon. I was getting the error, ‘fatal: no user ‘postgres;’ was found’. I was debugging the issue from last night. For a postgres novice like me it was a little bit difficult to finally find the issue. Hope you will update the article soon.

Nevertheless, this was an amazing article. Now going to create my own REST APIs. Thank you so much again.

@clintpaul89 Thanks very much for your post. Were you able to get your code to work after you removed the semicolon, or were you still having issues? Just wondering.

1 Like

Yes. It worked like a charm after I removed the semicolon. :grinning:

1 Like

@clintpaul89 Good to hear!

The best tutorial for Ktor I’ve ever seen. A big thanks to the author! :hearts:

I am getting this error:

org.postgresql.util.PSQLException: The server requested password-based authentication, but no password was provided.

What should I do?

You should change pg_hba.conf as written here:


and add this code:
config.password = “your-pass”
to hikari()

Thanks for the great tutorial. It is one of those best tutorials I’ve seen.

There is a bug/error in the solution code (calling this function will delete all the todo entries):
override suspend fun deleteTodo(userId: Int, todoId: Int) {
dbQuery {
Todos.deleteWhere {
Todos.id.eq(todoId)
Todos.userId.eq(userId)
}
}
}

it should be using org.jetbrains.exposed.sql.and
Todos.deleteWhere {
Todos.id.eq(todoId) and Todos.userId.eq(userId)
}

@kevindmoore Can you please help with this when you get a chance? Thank you - much appreciated! :]

@dwalk Thanks for the catch. I’ve updated the downloadable projects

I am getting this error with Postman following the code, I’ve double checked everything. Any tips as how I can debug this: ERROR Application - Unhandled: POST - /v1/users/create

Are you sure that you’ve created this route? Make sure it is hooked up

1 Like

I think I had an incorrect header param, which then fixed the issue. However, I am getting one more bug now, I am able to add a user to the data base, but the Route.users still throws a 500 error because on this line call.sessions.set(MySession(userId)) I get this exception, I can’t seem to wrangle it:

java.lang.IllegalArgumentException: Session data for type class com.raywenderlich.Authentication.MySession was not registered