Skip to main content

08-07-2019_Week3_Monday

(Create user called newuser and password as 'password')
mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password' ;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost' BY 'password';

(creating database called details.)
mysql> CREATE DATABASE details;

mysql> use details
Database changed

(creating a Table called example and coloumn names of firstname , lastname ,email all having intermediate length of 100)
mysql>CREATE TABLE example (firstname VARCHAR(100),lastname VARCHAR(100) ,email VARCHAR(100))


Next task is to get the data from the data base we created .


Creating an spring rest API to communicate through mongoDB and using POSTMAN to check http request.

Softwares used:

  • Spring Data Rest
  • Spring Boot
  • Spring rest API server
  • Postman


















ref: https://docs.spring.io/spring/docs/2.0.x/reference/jdbc.html

started mongoDB and . Created the called rest_tutorial


> mongo   
> use rest_tutorial
> show dbs (shows the db s in mongo db)
> show collections
> show tables
> db.getCollectionNames() //gets the names of the collection you have
> db.database.find() //displays a list of records matching 

> db.createUser({"user": "ajitesh", "pwd": "gurukul", "roles": ["readWrite", "dbAdmin"]})
(creatinng user called ajitesh with password gurukul )
>db.pets.drop();   (deletes the collection called pets.)

useful to start he mongo server

>sudo service mongod start 
>netstat -plntu (to check whether the port is listening)
usual port of Mongodb is 27017


GET method working DELETE method working PUT method working When POST method working it gave an error what happened was a simple "/" was missing from the url address
http://localhost:8080/pets wrong
http://localhost:8080/pets/ correct


Connecting Web App to API for calling GET,POST,DELETE

For this we need a client to sent GET,POST,DELETE requests to REST API.


ref: https://spring.io/blog/2009/03/27/rest-in-spring-3-resttemplate

     org.springframework.web.client 

The main problem we come across is what are the steps to connect the webapp to the API server side. 
For this we have couple of methods that can be used.
  • using http client service HttpClient REST 
    • http client connection management
    • http.HttpEntitiy
    • http.HttpResponse
    • http.client.HttpClient
    • http.client.HttpGet
    • http.impl.client.DefaultHettpClient
  • RestTemplate supported by Spring
postForLocation  public URI postForLocation(String url, Object request, Object... urlVariables)

getForObject public <T> T getForObject(String url, Class<T> responseType, Object... urlVariables)

delete    public void delete(String url,Object... urlVariables
put public void put(String url,Object request, Object... urlVariables)

String result = restTemplate.getForObject("http://example.com/hotels/{hotel}/bookings/{booking}", String.class,"42", "21");
will perform a GET on http://example.com/hotels/42/bookings/21




Comments

Popular posts from this blog

Hackerank Q&A

HACKERANK SQL PROBLEMS. Question: Generate the following two result sets: Query an  alphabetically ordered  list of all names in  OCCUPATIONS , immediately followed by the first letter of each profession as a parenthetical (i.e.: enclosed in parentheses). For example:  AnActorName(A) ,  ADoctorName(D) ,  AProfessorName(P) , and  ASingerName(S) . Query the number of ocurrences of each occupation in  OCCUPATIONS . Sort the occurrences in  ascending order , and output them in the following format: There are a total of [occupation_count] [occupation]s. where  [occupation_count]  is the number of occurrences of an occupation in  OCCUPATIONS  and  [occupation]  is the  lowercase  occupation name. If more than one  Occupation  has the same  [occupation_count] , they should be ordered alphabetically Answer:   select ( case when occupation= "Doctor" then concat( name ...

git

git is a useful platform for software project management where it gives you speed and efficiency when handling larger or smaller projects. git keeps track of your workflow and editing ,branching , merging and debugging the code is granted to different users. git config git config –global user.name “[name]” git config –global user.email “[email address]” git init  initiates git git clone clones git project to the current directory git add adding files to the staging area. git commit git commit -m “[ Type in the commit message]” records the files in the staging area permanently in the history git diff shows the files differences which are not yet staged git diff –staged This command shows the differences between the files in the staging area and the latest version present. git diff [first branch] [second branch] git commit -a This command commits any files you’ve added with the git add command and also commits any files you’ve changed since ...

10-09-2019_Week3-Wednesday

Creating a WebAPP of Movies to show Actors and movies Home Page Tabs Movies Actors. Buttons Add movie > movie submit Form Add actor > Actor submit Form Databases/Submit Forms Movies Name Year Genere Actors Description Image Actors Name fname last name  Date of birth  Description