Coder Social home page Coder Social logo

go-react-blog's Introduction

// PLAY LIST : https://www.youtube.com/playlist?list=PL0wd2rfixHH23Ej7qVSrbgr-yhI6iSC05

package adress // https://docs.gofiber.io/

mkdir go-react-blog
cd go-react-blog/
mkdir server
mkdir client
cd server/
go-react-blog/server$ go mod init github.com/blalyasar/go-react-blog
go-react-blog/server$ go get github.com/gofiber/fiber/v2
go-react-blog/server$ go run server.go 
go-react-blog/server$ go get -u gorm.io/gorm
go-react-blog/server$ go get -u gorm.io/driver/mysql

Second Video: // https://www.youtube.com/watch?v=PPsTNQpT3e0&list=PL0wd2rfixHH23Ej7qVSrbgr-yhI6iSC05&index=2

MariaDB [(none)]> CREATE DATABASE fiberblog;

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| fiberblog          |

After Created

MariaDB [fiberblog]> show tables;
+---------------------+
| Tables_in_fiberblog |
+---------------------+
| blogs               |

MariaDB [fiberblog]> explain blogs;
+-------+---------------------+------+-----+---------+----------------+
| Field | Type                | Null | Key | Default | Extra          |
+-------+---------------------+------+-----+---------+----------------+
| id    | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
| title | varchar(255)        | NO   |     | NULL    |                |
| post  | longtext            | YES  |     | NULL    |                |
+-------+---------------------+------+-----+---------+----------------+

3.VIDEO: https://www.youtube.com/watch?v=2fonkDhlPIs&list=PL0wd2rfixHH23Ej7qVSrbgr-yhI6iSC05&index=3

After video3 $ curl -X POST http://localhost:8000

{"msg":"Blog Create","statusText":"Ok"}

$ curl localhost:8000

{"msg":"Blog List","statusText":"Ok"}

$ curl -X PUT http://localhost:8000

{"msg":"Blog Update","statusText":"Ok"}

$ curl -X DELETE http://localhost:8000 {"msg":"Blog Delete from given id","statusText":"Ok"}

4.VIDEO BEFORE 4.VIDEO CREATE MYSQL DATA IN TABLES....


MariaDB [fiberblog]> 

MariaDB [fiberblog]> INSERT INTO `blogs` (`id`,`title`,`post`) VALUES (NULL, 'FIRST BLOG',  'FIRST POST');
Query OK, 1 row affected (0.002 sec)

MariaDB [fiberblog]> INSERT INTO `blogs` (`id`,`title`,`post`) VALUES (NULL, 'SECOND BLOG',  'SECOND POST');

Query OK, 1 row affected (0.001 sec)

MariaDB [fiberblog]> SELECT * from blogs;

+----+-------------+-------------+
| id | title       | post        |
+----+-------------+-------------+
|  1 | FIRST BLOG  | FIRST POST  |
|  2 | SECOND BLOG | SECOND POST |
+----+-------------+-------------+
2 rows in set (0.000 sec)

After blog.go update list data.... and dont forget data is list..

curl -X GET http://localhost:8000

{"blog_records":[{"id":1,"title":"FIRST BLOG","post":"FIRST POST"},{"id":2,"title":"SECOND BLOG","post":"SECOND POST"}],"msg":"Blog List","statusText":"Ok"}

5.VIDEO: go get github.com/joho/godotenv

Add .env file in server directory for db info

db_user=""
db_password="...."
db_name="fiberblog"

6.VIDEO:

$curl -X POST --header "Content-Type: application/json"  --data '{"title":"newtitle","post":"new post"}'   http://localhost:8000
{"data":{"id":6,"title":"newtitle","post":"new post"},"msg":"Record is saved successfuly.","statusText":"Ok"

$ curl -X GET http://localhost:8000
{"blog_records":[{"id":1,"title":"FIRST BLOG","post":"FIRST POST"},{"id":2,"title":"SECOND BLOG","post":"SECOND POST"},{"id":3,"title":"","post":""},{"id":4,"title":"","post":""}],"msg":"Blog List","statusText":"Ok"}
:~$ 

7.VIDEO

put examples

curl -X GET http://localhost:8000
{"blog_records":[{"id":1,"title":"FIRST BLOG","post":"FIRST POST"},{"id":2,"title":"SECOND BLOG","post":"SECOND POST"},{"id":7,"title":"newtitle","post":"new post"},{"id":8,"title":"newtitle","post":"new post"},{"id":9,"title":"newtitle updated444","post":"new post updated 444"},{"id":10,"title":"newtitle updated444","post":"new post updated 444"}],"msg":"Blog List","statusText":"Ok"}


curl -X PUT --header "Content-Type: application/json"  --data '{"title":"newtitle updated444 TO 555","post":"new post updated 444 TO 555"}'   http://localhost:8000/9
{"data":{"id":9,"title":"newtitle updated444 TO 555","post":"new post updated 444 TO 555"},"msg":"record updated successfully","statusText":"Ok"}


curl -X GET http://localhost:8000
{"blog_records":[{"id":1,"title":"FIRST BLOG","post":"FIRST POST"},{"id":2,"title":"SECOND BLOG","post":"SECOND POST"},{"id":7,"title":"newtitle","post":"new post"},{"id":8,"title":"newtitle","post":"new post"},{"id":9,"title":"newtitle updated444 TO 555","post":"new post updated 444 TO 555"},{"id":10,"title":"newtitle updated444","post":"new post updated 444"}],"msg":"Blog List","statusText":"Ok"}

8.VIDEO DELETE METHOD


$ curl -X GET http://localhost:8000
{"blog_records":[{"id":1,"title":"FIRST BLOG","post":"FIRST POST"},{"id":2,"title":"SECOND BLOG","post":"SECOND POST"},{"id":7,"title":"newtitle","post":"new post"},{"id":8,"title":"newtitle","post":"new post"}],"msg":"Blog List","statusText":"Ok"}

$ curl -X DELETE --header "Content-Type: application/json"    http://localhost:8000/8
{"msg":"Record deleted successfuly","statusText":"Ok"}
$ 

$ curl -X GET http://localhost:8000
{"blog_records":[{"id":1,"title":"FIRST BLOG","post":"FIRST POST"},{"id":2,"title":"SECOND BLOG","post":"SECOND POST"},{"id":7,"title":"newtitle","post":"new post"}],"msg":"Blog List","statusText":"Ok"}

9.VIDEO


resource:
https://react-bootstrap.github.io/
https://axios-http.com/docs/intro 

npx create-react-app client
cd client
npm install react-bootstrap bootstrap 
npm install axios


10.VIDEO: REACT APP AND API REQUEST Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8000/. (Reason: CORS request did not succeed). Status code: (null).

CREATE .env file in client directory and write localhost and created gitignore file

go-react-blog's People

Contributors

blalyasar avatar

Watchers

 avatar

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.