Skip to content

rajnishsubedi0/postgres_rust_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1) First of all setup database named "test" on postgres as mentioned on .env file. You can name any variable any thing.

2) Generate postgres table with following code on test named database from terminal.

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR NOT NULL,
    email VARCHAR UNIQUE NOT NULL
);
  1. After that enter diesel print-schema > src/schema.rs on terminal to generate schema.rs file as per your postgres table configuration. You can delete schema.rs from this clone and can generate that with that command.
  2. Then enter cargo run
  3. To get users enter
curl http://127.0.0.1:8080/users

or can open from browser with

localhost:8080/users

To add users enter

curl -X POST http://127.0.0.1:8080/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "email": "alice@example.com"}'

or You can also send data from rest api client on json format.

About

This is working postgres_rust_api

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages